I have a wpf application where I am using a side menu. In one section of the menu I have a Header menuitem and two sub menuitems. I change the background on the two sub menuitems to show a difference. There is a slight gap between the two sub menuitems with a different color. I want the background of both sub menuites to be the same with not gap in between. Here is my menu code:
<MenuItem x:Name="miReplaceLF" Header="Replace Line Feeds" Height="24" VerticalAlignment="Center"
ToolTip="Replace all line feeds in choosen fields with the replacement character." />
<MenuItem x:Name="smiDBFile" Header="DataBase Table"
Click="MenuItem_Click_RLFDBDatabase" Background="#FFBEEBF7"
Margin="15,0,0,0"
ToolTip="Replace line feeds on fields in a database table." />
<MenuItem x:Name="smiExcelTextFile" Header="Excel or Text File" Height="24"
VerticalAlignment="Top" Click="MenuItem_Click_RLFExcelText" Background="#FFBEEBF7"
Margin="15,0,0,0"
ToolTip="Choose a Excel/Text File." />
I tried putting the two sub menuitems within a stackpanel. This gives me the ability to have the uniform background I want but the sub menuitems are shifted to the right way too much. I just want a small indent on the two sub menuitem. I can't find a way to get the menuitems alligned to the left. Here is the code with the stackpanel.
<MenuItem x:Name="miReplaceLF" Header="Replace Line Feeds" Height="24" VerticalAlignment="Center"
ToolTip="Replace all line feeds in choosen fields with the replacement character." />
<StackPanel Background="#FFBEEBF7">
<MenuItem x:Name="smiDBFile" Header="DataBase Table"
Click="MenuItem_Click_RLFDBDatabase" Background="#FFBEEBF7"
Margin="0,0,0,0"
ToolTip="Replace line feeds on fields in a database table." />
<MenuItem x:Name="smiExcelTextFile" Header="Excel or Text File" Height="24"
Click="MenuItem_Click_RLFExcelText" Background="#FFBEEBF7"
Margin="0,0,0,0"
ToolTip="Choose a Excel/Text File." />
</StackPanel>
Here is the full XAML code, this has been changed to use the suggestions by Ed Plunkett
<Window x:Class="TextUtilities.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TextUtilities"
mc:Ignorable="d"
Title="Text Utilites" x:Name="TextUtils" Height="420" Width="900" Left="100" Top="30"
ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Background="#FFDBF4FB">
<Window.Resources>
<Style
TargetType="MenuItem"
BasedOn="{StaticResource {x:Type MenuItem}}"
x:Key="RLFItem">
<Setter Property="Margin" Value="15,0,0,0" />
<Setter Property="Background" Value="#FFBEEBF7" />
</Style>
</Window.Resources>
<Grid>
<Menu HorizontalAlignment="Left" Width="150" Margin="0,2,0,0" FontFamily="Arial" FontSize="14.667"
BorderThickness="0,2,2,0" BorderBrush="#FFE0E0E0" Background="#FFDBF4FB">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel x:Name="spItemsPanel" Background="#FFDBF4FB" />
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem x:Name="miReplaceLF" Header="Replace Line Feeds" Height="24" VerticalAlignment="Center"
ToolTip="Replace all line feeds in choosen fields with the replacement character."/>
<MenuItem x:Name="smiDBFile" Header="DataBase Table" Height="24"
Style="{StaticResource RLFItem}" Click="MenuItem_Click_RLFDBDatabase"
ToolTip="Replace line feeds on fields in a database table." />
<MenuItem x:Name="smiExcelTextFile" Header="Excel or Text File" Height="24"
Style="{StaticResource RLFItem}" Click="MenuItem_Click_RLFExcelText"
ToolTip="Choose a Excel/Text File." />
<MenuItem x:Name="miCreateLF" Header="Create Line Feeds" Height="24" VerticalAlignment="Center" ToolTip="Replace all the replacement characters with line feeds." />
<MenuItem x:Name="miViewTextField" Header="View Text Field" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_ViewTextField" ToolTip="Display the contents of a text field. Allows you to see how the data will be displayed in the UI." />
<MenuItem x:Name="miViewSPTEXT" Header="View SPTEXT" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_ViewSPTEXT" ToolTip="Display field sptd_text from table sptextdt. Allows you to see how the data will be displayed in the UI." />
<MenuItem x:Name="miSPlitLargeFile" Header="Split Large File" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_SLF" ToolTip="Split large files, over 60MB into smaller files." />
<MenuItem x:Name="miHowTo" Header="How To" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_HowTo" ToolTip="Instructions on how to use the SPText Utilities." />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
<MenuItem Header="Close" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_Close" />
</Menu>
<Grid x:Name="grdRLFDatabase" Visibility="Visible" Height="350" Margin="155,0,0,0" VerticalAlignment="Top">
<TextBox x:Name="txtRLFDBTitle" IsReadOnly="True" TextWrapping="Wrap"
Text="Process to clean a database table and create a pipe delimited text file. You may type in a server instance or select one from the list. Once a server is choosen please cliack the 'Load DB Info' button."
HorizontalAlignment="Left" Height="62" Margin="10,4,0,0" VerticalAlignment="Top" Width="659" FontFamily="Arial"
FontSize="16" Padding="5,1,1,1" Background="#FFDBF4FB" BorderBrush="Gray" BorderThickness="1"/>
<Label x:Name="lblRLFDBInstance" Content="Enter Database Instance:" HorizontalAlignment="Left" Height="28" Margin="5,87,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<ComboBox x:Name="cbxRLFDBInstances" x:FieldModifier="public" HorizontalAlignment="Left" Height="28" Margin="189,87,0,0" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" IsEditable="True"/>
<Button x:Name="btnRLFDBLoadDBInfo" Content="Load DB Info" HorizontalAlignment="Left" Height="26" Margin="475,89,0,0" VerticalAlignment="Top" Width="101" FontFamily="Arial" FontSize="14.667" Click="btnRLFDBLoadDBInfo_Click" Background="#FFEEFFFF" ToolTip="Click here after choosing or typing in the datbase instance. This will populate the database list."/>
<Label x:Name="lblRLFDBName" Content="Choose Database:" HorizontalAlignment="Left" Height="28" Margin="5,131,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<ComboBox x:Name="cbxRLFDBName" x:FieldModifier="public" HorizontalAlignment="Left" Height="28" Margin="189,132,0,0" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" IsEditable="True" SelectionChanged="cbxRLFDBName_SelectionChanged" ToolTip="Once a database is choosen the table list will automatically be populated."/>
<Label x:Name="lblRLFDBTableName" Content="Choose Table:" HorizontalAlignment="Left" Height="28" Margin="5,176,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<ComboBox x:Name="cbxRLFDBTableName" x:FieldModifier="public" HorizontalAlignment="Left" Height="28" Margin="189,177,0,0" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" IsEditable="True" />
<Label x:Name="lblRLFDBOutputName" Content="Choose Output Folder:" HorizontalAlignment="Left" Height="28" Margin="5,233,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<TextBox x:Name="txtRLFDBOutputFolder" x:FieldModifier="public" IsReadOnly="True" HorizontalAlignment="Left" Height="50" Margin="189,222,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" />
<Button x:Name="btnRLFDBBrowseFolder" Content="Browse..." x:FieldModifier="public" HorizontalAlignment="Left" Height="26" Margin="475,235,0,0" VerticalAlignment="Top" Width="74" FontFamily="Arial" FontSize="14.667" Background="#FFEEFFFF" Click="btnRLFDBBrowseFolder_Click" ToolTip="Choose the folder where the text file will be saved to. The file will be named the same as a the table with '_duc' appended to the end."/>
<Button x:Name="btnRLFDBSubmit" Content="Submit" x:FieldModifier="public" HorizontalAlignment="Left" Height="26" Margin="261,300,0,0" VerticalAlignment="Top" Width="74" FontFamily="Arial" FontSize="14.667" Background="#FFEEFFFF" Click="btnRLFDBSubmit_Click"/>
</Grid>
<Grid x:Name="grdRLFExcelText" Visibility="Hidden" Height="320" Width="750" Margin="150, 0, 0 0" VerticalAlignment="Top">
<Label x:Name="lblRLFFileInfo" Content="Process to replace Line Feeds in text fields." HorizontalAlignment="Left" Margin="3,15,0,0" VerticalAlignment="Top" Width="583" Height="30" FontFamily="Arial" FontSize="18.667" FontWeight="Bold"/>
<Label x:Name="lblRLFFileName" Content="Enter the filename:" HorizontalAlignment="Left" Margin="3,79,0,0" VerticalAlignment="Top" Width="162" Height="30" FontFamily="Arial" FontSize="16"/>
<TextBox x:Name="txtRLFFileName" HorizontalAlignment="Left" Height="50" Margin="186,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="400" VerticalContentAlignment="Center" FontFamily="Arial" FontSize="16" FontWeight="Bold" Background="#FFDBF4FB" TextChanged="txtRLFFileName_TextChanged" />
<Button x:Name="btnRLFFileBrowse" Content="Browse..." HorizontalAlignment="Left" Margin="630,84,0,0" VerticalAlignment="Top" Width="89" FontFamily="Arial" FontSize="16" Background="#FFDBF4FB" Click="btnRLFFileBrowse_Click"/>
<Label x:Name="lblRLFOutputFolder" Content="Choose output folder:" HorizontalAlignment="Left" Margin="3,149,0,0" VerticalAlignment="Top" Width="180" Height="30" FontFamily="Arial" FontSize="16"/>
<TextBox x:Name="txtRLFOutputFolder" HorizontalAlignment="Left" Height="50" Margin="186,138,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="400" VerticalContentAlignment="Center" FontFamily="Arial" FontSize="16" FontWeight="Bold" Background="#FFDBF4FB" TextChanged="txtRLFOutputFolder_TextChanged"/>
<Button x:Name="btnRLFFolderBrowse" Content="Browse..." HorizontalAlignment="Left" Margin="630,154,0,0" VerticalAlignment="Top" Width="89" FontFamily="Arial" FontSize="16" Background="#FFDBF4FB" Click="btnRLFFolderBrowse_Click"/>
<Label x:Name="lblRLFFieldDelim" Content="Field Delimiter:" HorizontalAlignment="Left" Margin="190,202,0,0" VerticalAlignment="Top" Width="118" Height="30" FontFamily="Arial" FontSize="16"/>
<TextBox x:Name="txtRLFFieldDelim" HorizontalAlignment="Left" Height="22" Margin="312,206,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="18" VerticalContentAlignment="Center" FontFamily="Arial" FontSize="16" FontWeight="Bold" Background="#FFDBF4FB" TextChanged="txtRLFFileName_TextChanged" MaxLength="2" HorizontalContentAlignment="Center" />
<CheckBox x:Name="chbxRLFHeaders" Content="Has Header Row" HorizontalAlignment="Left" Height="17" Margin="430,208,0,0" VerticalAlignment="Top" Width="149" FontFamily="Arial" FontSize="16" Checked="chbxRLFHeaders_Checked" Unchecked="chbxRLFHeaders_Unchecked"/>
<Button x:Name="btnRLFSubmit" Content="Submit" HorizontalAlignment="Left" Margin="319,259,0,0" VerticalAlignment="Top" Width="82" Height="31" Background="#FFDBF4FB" FontFamily="Arial" FontSize="16" Click="btnRLFSubmit_Click"/>
</Grid>
</Grid>
</Window>
You can create a MenuItem style which changes Padding or Margin (your choice; try both) and background color for the menu items you apply it to, and then set it on whichever items you chose:
<Window.Resources>
<Style
TargetType="MenuItem"
BasedOn="{StaticResource {x:Type MenuItem}}"
x:Key="SpecialItem"
>
<Setter Property="Margin" Value="15,0,0,0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="#FFBEEBF7" />
</Style>
</Window.Resources>
...
<MenuItem Header="Foo" />
<MenuItem Header="Bar" Style="{StaticResource SpecialItem}" />
<MenuItem Header="Baz" Style="{StaticResource SpecialItem}" />
The mouse-hover state for those will look a little funny, unfortunately. With the default WPF MenuItem template, or at least the one I'm seeing here, you need to replace the entire control template to change that. We can go there if you need to; let me know.
Update
How to add an image to a Stack Overflow question: Edit the question, then click the "add picture" icon which is highlighted in orange.
Related
I have a toolbar in my WPF window as shown in bellow, please help me change labels foreground color dynamically in code behind.
Thanks...
<DockPanel Height="60" VerticalAlignment="Top">
<ToolBar Name="MyToolBar" DockPanel.Dock="Top" Height="60" VerticalAlignment="Top" FlowDirection="RightToLeft"
FontFamily="Calibri" FontSize="16" FontWeight="Bold" Background="#FFEEF5FD" Foreground="Black" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<Button Name="BtnSubmit" Style="{DynamicResource TStyle}" Click="BtnSubmit_Click" Tag="New" Height="52" Width="60"
IsDefault="True" Margin="0,0,0,1">
<StackPanel Margin="0" Height="54"
<Image Source="/Img/Save 04.png" Height="25" Margin="16,0"/>
<Label Content="Save" Margin="0,0,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button Name="BtnApply" Style="{DynamicResource TStyle}" Click="BtnApply_Click" Tag="New" Height="52"
IsDefault="True" Margin="0,1,0,2" Width="85">
<StackPanel Margin="0" Height="52" Width="82">
<Image Source="/Img/ApplyIcon.png" Height="25" Margin="29,0,26,0"/>
<Label Content="Edit" Margin="-15,0,-23,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</ToolBar>
</DockPanel>
To change the Foreground of all TextBlock elements you must define a Brush resource and assign it to all relevant TextBlock elements using {DynamicResource}:
MainWindow.xaml
<Window>
<Window.Resources>
<SolidColorBrush x:Key="ButtonLabelForegroundBrush" Color="Black" />
</Window.Resources>
<DockPanel>
<ToolBar>
<Button>
<TextBlock Foreground="{DynamicResource ButtonLabelForegroundBrush}" />
</Button>
</ToolBar>
</DockPanel>
</Window>
MainWindow.xaml.cs
private void ChangeTextBlockForeground()
{
var brush = FindResource("ButtonLabelForegroundBrush") as SolidColorBrush;
brush.Color = Colors.Red;
}
I've been working on how to do layouts and I've come across something that is bugging the heck out of me. Now, if I use the code below, the window takes up the entirety of my screen.
<Window x:Class="HDD_Drill_View.Windows.WndwMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="HDDC"
WindowStartupLocation="CenterScreen"
Name="wndwMain"
Closing="WindowClosing"
ResizeMode="NoResize"
WindowState="Normal"
SizeToContent="WidthAndHeight">
<Grid>
<DockPanel Width="Auto"
LastChildFill="False"
HorizontalAlignment="Left">
<DockPanel.Background>
<ImageBrush ImageSource="..\Resources\background.png"
Stretch="UniformToFill"
TileMode="None" />
</DockPanel.Background>
<StackPanel DockPanel.Dock="Top"
Height="Auto"
Width="Auto"
Orientation="Horizontal"
HorizontalAlignment="Center">
<Button HorizontalAlignment="Left"
Name="bttnGenerateReports"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnGenerateReportsClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text="Generate" /><LineBreak /><Run Text=" Reports" /></TextBlock>
</Button>
<Button HorizontalAlignment="Left"
Name="bttnSurveyReport"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnSurveyReportClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text="Survey" /><LineBreak /><Run Text="Report" /></TextBlock>
</Button>
<Button HorizontalAlignment="Left"
Name="bttnTimeChart"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnTimeChartClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text=" Time" /><LineBreak /><Run Text=" Chart" /></TextBlock>
</Button>
<Button HorizontalAlignment="Left"
Name="bttnMaterialAcquisition"
VerticalAlignment="Top"
UseLayoutRounding="False"
Click="BttnMaterialAcquisitionClick"
Margin="10">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"><Run Text=" Material" /><LineBreak /><Run Text="Acquistion" /></TextBlock>
</Button>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom"
Height="Auto"
Width="Auto"
Orientation="Horizontal">
<!--MaxWidth="800"
MaxHeight="80"-->
<StackPanel.Background>
<ImageBrush ImageSource="..\Resources\drildata2.jpg" />
</StackPanel.Background>
</StackPanel>
</DockPanel>
</Grid>
</Window>
Yet, if I uncomment the Max Height and Max Width in the last StackPanel, then it seems fine. Basically, I'm wanting my background image to NOT affect my window size. Is this possible? I'm trying to set the background of a StackPanel to an image.
Remove the SizeToContent="WidthAndHeight" from the Window.
I want to stretch the Groupbox of this window (height). I am not able to get it working. What am I doing wrong?
What I want is that the groupbox stretches to the height of the window, but that the first column doesn't stretch.
<!-- PLAYER A -->
<Border Grid.Row="0" Grid.Column="0" x:Name="PlayerA" Height="145" VerticalAlignment="Center">
<Grid Height="145" VerticalAlignment="Top">
<GroupBox x:Name="grpPlayerA" Header="Player A" Margin="10,14,0,0" RenderTransformOrigin="0.035,-0.717" Height="127" VerticalAlignment="Top">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Label x:Name="lblArtistA" Content="VENGABOYS" HorizontalAlignment="Left" Margin="3,3,0,0" VerticalAlignment="Top"/>
<Label x:Name="lblTitleA" Content="TO BRAZIL" HorizontalAlignment="Left" Margin="3,27,0,0" VerticalAlignment="Top"/>
<ProgressBar x:Name="prgPlayerA" HorizontalAlignment="Left" Height="15" Margin="5,53,0,0" VerticalAlignment="Top" Width="212"/>
<Image x:Name="imgPlayerA" HorizontalAlignment="Left" Height="62" Margin="220,6,0,0" VerticalAlignment="Top" Width="81"/>
<Button x:Name="btnPlayerAPlay" Content="Play" HorizontalAlignment="Left" Margin="5,79,0,0" VerticalAlignment="Top" Width="75"/>
<Button x:Name="btnPlayerAPauze" Content="Pauze" HorizontalAlignment="Left" Margin="92,79,0,0" VerticalAlignment="Top" Width="74"/>
<Button x:Name="btnPlayerAStop" Content="Stop" HorizontalAlignment="Left" Margin="178,79,0,0" VerticalAlignment="Top" Width="76"/>
</Grid>
</GroupBox>
</Grid>
</Border>
<!-- PLAYER B-->
<Border Grid.Row="0" Grid.Column="1" x:Name="PlayerB">
<GroupBox x:Name="grpPlayerB" Header="Player B" Margin="0,14,16,0" Height="127" VerticalAlignment="Top">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Label x:Name="lblArtistB" Content="VENGABOYS" HorizontalAlignment="Left" Margin="3,3,0,0" VerticalAlignment="Top"/>
<Label x:Name="lblTitleB" Content="TO BRAZIL" HorizontalAlignment="Left" Margin="3,27,0,0" VerticalAlignment="Top"/>
<ProgressBar x:Name="prgPlayerB" HorizontalAlignment="Left" Height="15" Margin="5,53,0,0" VerticalAlignment="Top" Width="212"/>
<Image x:Name="imgPlayerB" HorizontalAlignment="Left" Height="62" Margin="220,6,0,0" VerticalAlignment="Top" Width="81"/>
<Button x:Name="btnPlayerBPlay" Content="Play" HorizontalAlignment="Left" Margin="5,79,0,0" VerticalAlignment="Top" Width="75"/>
<Button x:Name="btnPlayerBPauze" Content="Pauze" HorizontalAlignment="Left" Margin="92,79,0,0" VerticalAlignment="Top" Width="74"/>
<Button x:Name="btnPlayerBStop" Content="Stop" HorizontalAlignment="Left" Margin="178,79,0,0" VerticalAlignment="Top" Width="76"/>
</Grid>
</GroupBox>
</Border>
<!-- HITLIJST -->
<Border Grid.Row="1" Grid.Column="0" x:Name="Hitlijst" VerticalAlignment="Top" Margin="0,0,0,28">
<Grid VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="0*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<GroupBox x:Name="grpPlaylist" Header="Hitlijst" Margin="10,0" Grid.RowSpan="2" Height="275">
<Grid VerticalAlignment="Top">
<ListBox x:Name="lbxHitlijst" Height="242" Margin="10,10,10,0" VerticalAlignment="Top">
<ListBoxItem Background="#FFF55F19" Content="1. Vengaboys - To Brazil (3:19)"/>
<ListBoxItem Background="#FFF91A1A" Content="2. Total Touch - Doo Be La Dee (3:60)"/>
<ListBoxItem Content="3. ATB - 9 PM Till I Come (3:33)"/>
</ListBox>
</Grid>
</GroupBox>
</Grid>
</Border>
<Border Grid.Row="1" Grid.Column="1" x:Name="Info">
<Grid>
<GroupBox x:Name="grpInfo" Header="Info" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Height="282" Width="324">
<Grid>
<TextBlock x:Name="txtLyrics" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Lyrics" VerticalAlignment="Top" Height="119" Width="292"/>
<GroupBox x:Name="grpInfoInfo" Header="Gegevens" HorizontalAlignment="Left" Margin="10,134,0,0" VerticalAlignment="Top" Height="116" Width="292">
<Grid>
<Label x:Name="lblAlbum" Content="ALBUM: Hitzone 1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.149,0.231"/>
<Label x:Name="lblYear" Content="JAAR: 1992" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top" RenderTransformOrigin="0,0.269"/>
<Label x:Name="lblArtists" Content="ARTIEST(EN): Vengaboys" HorizontalAlignment="Left" Margin="10,62,0,0" VerticalAlignment="Top"/>
</Grid>
</GroupBox>
</Grid>
</GroupBox>
</Grid>
</Border>
<GroupBox x:Name="grpHitlijst" Header="Hitlijst --" Grid.ColumnSpan="2" Grid.RowSpan="2" Margin="0,0,10,10"/>
</Grid>
It would be great to get it working, thanks in advance!
If you want the GroupBox to stretch in height, why is your VerticalAlignment Top? Switch it to Stretch and it should work.
Please refer to this note:
WPF Groupbox height needs to change dynamically?
bottom line - set width and height to "Auto" (delete the values that they have),
and set the VerticalAlignment / Horizontal one if you need it too to "Stretch"
I have implemented a ScrollViewer around the content panel grid in my Windows Phone 7 page. However, whenever I try and scroll down to the bottom of the page, it snaps right back to it's original position the moment I take my finger off the screen. In other words on scrolling it does not retain it's last position rendering the scroll pointless.
This is my page code:
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71" x:Class="StepsForWater.Views.Submit"
mc:Ignorable="d"
d:DesignWidth="480"
d:DesignHeight="696"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"
Orientation="Portrait"
shell:SystemTray.IsVisible="True"
DataContext="{Binding Submit, Source={StaticResource Locator}}">
<!-- Sample code showing usage of ApplicationBar -->
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton x:Name="appbar_About" IconUri="/Images/appbar_button1.png" Text="About" Click="appbar_About_Click"/>
<shell:ApplicationBarIconButton x:Name="appbar_WalkRun" IconUri="/Images/appbar_button2.png" Text="Walk/Run" Click="appbar_WalkRun_Click"/>
<!--<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem x:Name="menuItem1" Text="MenuItem 1"></shell:ApplicationBarMenuItem>
<shell:ApplicationBarMenuItem x:Name="menuItem2" Text="MenuItem 2"></shell:ApplicationBarMenuItem>
</shell:ApplicationBar.MenuItems>-->
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="/StepsForWater;component/Images/submit-bg.png" />
</Grid.Background>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel"
Grid.Row="0"
Margin="12,17,0,28">
<!--<TextBlock x:Name="ApplicationTitle"
Text="MY APPLICATION"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock x:Name="PageTitle"
Text="page name"
Margin="9,-7,0,0"
Style="{StaticResource PhoneTextTitle1Style}" />-->
</StackPanel>
<ScrollViewer>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,-241" Background="{x:Null}">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,57,0,0" x:Name="tBlk_Username" Text="{Binding UserName}" VerticalAlignment="Top" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="27,79,0,0" x:Name="tb_UserNameVal" Text="{Binding UserNameValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,169,0,0" x:Name="tBlk_Email" Text="{Binding Email}" VerticalAlignment="Top" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,278,0,0" x:Name="tBlk_Message" Text="{Binding Message}" VerticalAlignment="Top" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="27,191,0,0" x:Name="tb_EmailVal" Text="{Binding EmailValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<TextBox Height="153" HorizontalAlignment="Left" Margin="27,300,0,0" x:Name="tb_MessageVal" Text="{Binding MessageValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<CheckBox Content="{Binding Location}" Height="72" HorizontalAlignment="Left" Margin="27,459,0,0" x:Name="chk_Location" VerticalAlignment="Top" />
<Button Content="{Binding Submit}" Height="72" HorizontalAlignment="Left" Margin="27,761,0,0" x:Name="btn_Submit" VerticalAlignment="Top" Width="160" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="SubmitClick" Command="{Binding SubmitCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBlock Height="30" HorizontalAlignment="Left" Margin="50,540,0,0" Name="tBlk_PicInfo" Text="{Binding PictureInfo}" VerticalAlignment="Top" Grid.Row="1" />
<Image Height="150" HorizontalAlignment="Left" Margin="50,583,0,0" Name="img_FlickrPic" Stretch="Fill" VerticalAlignment="Top" Width="200" Grid.Row="1" Source="{Binding ImageSource}"/>
<Button Content="Capture" Height="72" HorizontalAlignment="Left" Margin="267,0,0,138" Name="btn_Capture" VerticalAlignment="Bottom" Width="160" d:LayoutOverrides="GridBox" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="CaptureClick" Command="{Binding CaptureCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</ScrollViewer>
</Grid>
Update: Fixed my problem, all I needed to do was to ensure that my scrollviewer's height was less than that of it's contained grid!
As mentioned by others you should probably rethink the way your making your layout. There are cleaner options. But to answer your question, there were two problems. The first is that you need to specify a Height on the ScrollViewer.
<ScrollViewer Height="760">
....
</ScrollViewer>
The second problem is the negative margin of 241 you have applied to the grid. Simply take that off. It's preventing anything within that range of being scrolled to.
<Grid x:Name="ContentPanel" Margin="12,0,12,0">
....
</Grid>
And that should do it.
I've noticed that the last items in my list box don't scroll up freely. They almost "bounce" when I try to move them up. The effect is even worse when I have the SIP active. I can't scroll the bottom items up the screen. They stay on the bottom of the screen and I can't see them (or they are partially blocked).
Any ideas on how to correct this situation?
<ListBox VerticalAlignment="Top">
<Grid>
<TextBox Height="72" Margin="109,10,0,0" HorizontalAlignment="Left" Name="txt1" Text="" VerticalAlignment="Top" TextWrapping="Wrap" Width="341" InputScope="Text"/>
<TextBox Height="72" Margin="109,70,267,0" HorizontalAlignment="Left" Name="txt2" Text="0" VerticalAlignment="Top" Width="80" InputScope="Number" />
<TextBox Height="72" Margin="0,70,73,0" HorizontalAlignment="Right" Name="txt3" Text="0" VerticalAlignment="Top" Width="80" InputScope="Number"/>
<TextBox Height="131" Margin="12,160,0,0" HorizontalAlignment="Left" Name="txt4" Text="" VerticalAlignment="Top" TextWrapping="Wrap" Width="438" InputScope="Text"/>
<TextBox Height="72" Margin="12,320,0,147" HorizontalAlignment="Left" Name="txt5" Text="" VerticalAlignment="Top" Width="438" InputScope="Text"/>
<TextBlock Height="30" Margin="47,30,333,0" Name="lbl1" Text="Dosage" VerticalAlignment="Top" />
<TextBlock Height="30" Margin="10,90,332,0" Name="lbl2" Text="Quantity" VerticalAlignment="Top" />
<TextBlock Height="30" Margin="0,90,142,0" Name="lbl3" Text="Refills" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<TextBlock Height="37" Margin="24,135,212,0" Name="lbl4" Text="Additional Instructions" VerticalAlignment="Top" />
<TextBlock Height="30" Margin="24,293,0,0" Name="lbl5" Text="Reason for Taking" HorizontalAlignment="Left" VerticalAlignment="Top" />
<TextBlock Height="30" Margin="24,385,0,0" Name="lbl6" Text="Consumption Frequency:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBlock FontWeight="Bold" Height="30" HorizontalAlignment="Left" Margin="27,417,0,0" Name="lblday1" Text="Sun" VerticalAlignment="Top" Width="37" />
<TextBlock FontWeight="Bold" Height="30" HorizontalAlignment="Left" Margin="83,417,0,0" Name="lblday2" Text="Mon" VerticalAlignment="Top" Width="46" />
<TextBlock FontWeight="Bold" Height="30" HorizontalAlignment="Right" Margin="0,417,272,0" Name="lblday3" Text="Tue" VerticalAlignment="Top" Width="37" />
<TextBlock FontWeight="Bold" Height="30" HorizontalAlignment="Left" Margin="203,417,0,0" Name="lblday4" Text="Wed" VerticalAlignment="Top" Width="46" />
<TextBlock FontWeight="Bold" Height="30" HorizontalAlignment="Left" Margin="263,417,0,0" Name="lblday5" Text="Thur" VerticalAlignment="Top" Width="46" />
<TextBlock FontWeight="Bold" Height="30" HorizontalAlignment="Left" Margin="329,417,0,0" Name="lblday6" Text="Fri" VerticalAlignment="Top" Width="37" />
<TextBlock FontWeight="Bold" Height="30" HorizontalAlignment="Left" Margin="388,417,0,0" Name="lblday7" Text="Sat" VerticalAlignment="Top" Width="37" />
<CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left" Margin="15,431,0,0" Name="chkSun" VerticalAlignment="Top" VerticalContentAlignment="Top" Width="59" />
<CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left" Margin="75,431,0,0" Name="chkMon" VerticalAlignment="Top" VerticalContentAlignment="Top" Width="59" />
<CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left" Margin="135,431,0,0" Name="chkTue" VerticalAlignment="Top" VerticalContentAlignment="Top" Width="59" />
<CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Right" Margin="0,431,202,0" Name="chkWed" VerticalAlignment="Top" VerticalContentAlignment="Top" Width="59" />
<CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left" Margin="255,431,0,0" Name="chkThu" VerticalAlignment="Top" VerticalContentAlignment="Top" Width="59" />
<CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left" Margin="315,431,0,0" Name="chkFri" VerticalAlignment="Top" VerticalContentAlignment="Top" Width="59" />
<CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left" Margin="375,431,0,0" Name="chkSat" VerticalAlignment="Top" VerticalContentAlignment="Top" Width="59" />
</Grid>
</ListBox>
UPDATE:
OK, I sort of answered my own question. At least I found an initial answer to my own question. What I did to correct the bouncing is to modify the height property in the .
<Grid Height="800">
Now when the SIP is active the bottom items are visible with plenty of room to spare.
As I said above, I found an answer. I don't know if it was the right answer. If you have a better way, please let me know.
When I was testing this, yes, when the SIP is active I can initially move freely to the bottom. However, when I move try to move back up I get the bounce effect again. Is there something that I need to add to allow it to move freely up and down?
The problem in general is that the Listbox doesn't know how tall it is. You can solve it by setting an explicit height on it's parent, sure. A better way to do it would be to define a row for it in the grid:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListBox Grid.Row="0">
...
</ListBox>
</Grid>
The Height="*" says the row should take the entire space of it's container.
OK, I answered my own question. At least I found an answer to my own question. What I did to correct the bouncing is to modify the height property in the .
<Grid Height="800">
Now when the SIP is active the bottom items are visible with plenty of room to spare.
As I said above, I found an answer. I don't know if it was the right answer. If you have a better way, please let me know.