I have a groupbox in my xaml file containing a Label, Image, DataGrid with two columns, a textbox and progressbar. But when I compile my form and run it, no control from this groupbox is displayed. However controls from other groupboxes are getting displayed.
Here is my my groupbox in xaml :
<GroupBox HorizontalAlignment="Left" Height="400" Margin="25,150,0,0" VerticalAlignment="Top" Width="411" BorderBrush="#FF0788F3" Style="{DynamicResource GroupBoxStyle1}" Grid.RowSpan="2">
<StackPanel Margin="-4,1,-5,-7" RenderTransformOrigin="0.5,0.5">
<Label Content="Text" x:Name="label4" Margin="6,40,242,0" VerticalAlignment="Top" FontFamily="Ebrima" FontSize="16" Padding="5" Background="#FF3053B0" FontWeight="Bold"/>
<Image x:Name="Image" HorizontalAlignment="Left" VerticalAlignment="Top" Width="62" Height="42" Margin="185,-30,0,0" />
<DataGrid x:Name="InstallableGrid" Margin="10,15,0,0" HeadersVisibility="Column" VerticalAlignment="Top" FontSize="14" Height="138" Background="#FFF5F3C7" RowBackground="#FF37AEC9" AlternatingRowBackground="LightBlue" CanUserAddRows="False" KeyboardNavigation.TabNavigation="None" AutoGenerateColumns="True" IsReadOnly="True" VirtualizingPanel.VirtualizationMode="Standard" HorizontalGridLinesBrush="Black" HorizontalAlignment="Left" Width="333" SelectionChanged="InstallableGrid_SelectionChanged">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Select" ElementStyle="{StaticResource CheckBoxStyleInverted}" />
</DataGrid.Columns>
</DataGrid>
<TextBox x:Name="PBarTimer" Background="#FFF5F3C7" Foreground="Red" HorizontalAlignment="Left" Height="20" Margin="10,45,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="55" FontSize="14" Padding="1,-1,1,1" RenderTransformOrigin="-0.249,0.84"/>
<ProgressBar x:Name="PBar" Background="#FFF5F3C7" HorizontalAlignment="Left" Height="20" Margin="75,-20,0,0" VerticalAlignment="Top" Width="268" IsIndeterminate="True" RenderTransformOrigin="0.596,0.765"/>
</StackPanel>
</GroupBox>
PS: I am a complete beginner in wpf, I am basically a Linux person so the problem I am committing here could be very silly and I did try googling this problem but could not find any help.
Related
I have a WPF application with a nice background picture. However, when I place some elements to the form I want them to be not so transparent.
For example simple groupbox:
<GroupBox x:Name="LocationGroup" Grid.Column="1" Grid.Row="1" Header="Location" HorizontalAlignment="Left" Height="100" Margin="10,90,0,0" VerticalAlignment="Top" Width="734">
<Grid Margin="1,1,1,1">
<Label Content="Location" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top"/>
<ComboBox x:Name="LocationCombo" HorizontalAlignment="Left" Margin="5,36,0,0" VerticalAlignment="Top" Width="100"
DisplayMemberPath="LocationDescr" SelectedValuePath="LocationNr" SelectedValue="{Binding Path=Location}">
</ComboBox>
</Grid>
</GroupBox>
I have tried setting the group box (and grid) opacity properties, but it only affects to the label and combo box opacity, not the background.
What I'm looking for is just like the element in the right in the picture linked below:
Opacity example
Here's one way you can achieve it:
<Grid>
<Grid.Background>
<ImageBrush ImageSource="path\to\backgroundimage" Stretch="UniformToFill"/>
</Grid.Background>
<Grid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" Height="100" Width="400" Margin="10,90,0,0" VerticalAlignment="Top">
<Grid Background="White" Opacity="0.5"></Grid>
<GroupBox x:Name="LocationGroup" Header="Location">
<Grid Margin="1,1,1,1">
<Label Content="Location" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top"/>
<ComboBox x:Name="LocationCombo" HorizontalAlignment="Left" Margin="5,36,0,0" VerticalAlignment="Top" Width="100"
DisplayMemberPath="LocationDescr" SelectedValuePath="LocationNr" SelectedValue="{Binding Path=Location}">
</ComboBox>
</Grid>
</GroupBox>
</Grid>
</Grid>
I got a a few Textblocks and a Datagrid in a grid. The Datagrid vertical scrollbar works fine. But when I put the grid inside a Viewbox the vertical scrollbar disappears. Below is my code
<Window x:Class=MyProject.View.MyTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStartupLocation="CenterScreen"
Title="{Binding FormTitle}" Height="500" Width="800" >
<Window.InputBindings>
<KeyBinding Key="F7" Command="{Binding PrintCommand}" />
</Window.InputBindings>
<Viewbox VerticalAlignment="Top" HorizontalAlignment="Left" Stretch="UniformToFill" >
<Grid Height="Auto" Width="Auto" Name="rootGrid">
<TextBlock Height="12" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBlock1" Text="Job ID:" VerticalAlignment="Top" />
<TextBlock Height="12" HorizontalAlignment="Left" Margin="12,28,0,0" Name="textBlock2" Text="Job Run Time:" VerticalAlignment="Top"/>
<TextBlock Height="12" HorizontalAlignment="Left" Margin="12,45,0,0" Name="textBlock3" Text="Run Number:" VerticalAlignment="Top" />
<TextBlock Height="12" HorizontalAlignment="Left" Margin="12,61,0,0" Name="textBlock4" Text="User Name:" VerticalAlignment="Top" />
<DataGrid CanUserAddRows="False" ItemsSource="{Binding ArchInfo}" AutoGenerateColumns="False"
CanUserDeleteRows="False" CanUserReorderColumns="False"
CanUserSortColumns="True" GridLinesVisibility="All"
ColumnHeaderHeight ="40"
Margin="5,124,5,0" IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Table Name" Binding="{Binding Path=TableName, UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTextColumn Header="Table Type" Binding="{Binding Path=TableType, UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTextColumn Header="Status" Binding="{Binding Path=Status, UpdateSourceTrigger=PropertyChanged}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Viewbox>
</Window>
If I add the following to the Datagrid the scrollbar will show but it does not function.
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
No matter what I do I can only see part of the Datagrid rows.
Any idea how to resolve this?
Thanks,
The problem has been resolved by Andy's comment.
Setting Datagrid Height and Stretch="Uniform" made it work. See Andy's comment.
I am currently sitting on a Silverlight-Listbox and have some
trouble getting my listBox right.
Its (visually) starts from the second item.
I have to scroll up to see the first one.
Why is this happening and how could I fix this?
<ListBox x:Name="ServingsList"
Foreground="White"
Background="#FFB88A8A"
SelectionChanged="servingSelected"
Margin="0,0,0,297">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="70" Width="432">
<Rectangle x:Name="Linie"
Fill="#FF8D8D8D"
HorizontalAlignment="Right"
Height="2"
StrokeThickness="0"
VerticalAlignment="Top"
Width="380"
Margin="0,-30,0,0" />
<TextBlock x:Name="ServingTitel"
TextWrapping="Wrap"
Text="{Binding name}"
FontSize="21.333"
Margin="50,-60,0,0" />
<Image x:Name="Ribbon"
HorizontalAlignment="Right"
Height="30"
VerticalAlignment="Top"
Width="151"
Source="/TEX/GrayRibbon.png"
Stretch="UniformToFill"
Margin="0,-60,0,0" />
<TextBlock x:Name="Kcal"
TextWrapping="Wrap"
Text="{Binding kalorien]}"
FontSize="18.667"
Height="23"
Margin="0,-92,8,0"
TextAlignment="Right" />
<Button Content="1"
Width="55" Height="55"
BorderThickness="3"
FontSize="18.667"
Padding="-1,-2,0,0"
Margin="-400,-87,0,0"
FontWeight="Bold"
Click="servingButtonClicked" />
</StackPanel>
</DataTemplate>
</ListBox>
You need to check your Margin values - in the main list you're putting 297 pixels of whitespace below your list box. Other elements have weird values too. Expression Blend sometimes messes with the Margins if you change from a StackPanel to a Grid.
e.g:
Margin="0,0,0,297">
I am in serious trouble. I have listbox control in which i have many combo box. whenever select the value in combo box, i have to make other controls as hidden. i am using MVVM pattren. i am unable to get the child controls from ListBox control but i can get the ListBox control in viewmodel. How can i get these controls in viewmodel? Is it possible? I am using framework 4.0. i have shown the code below which write in view.
<ListBox x:Name="lstItems" MaxHeight="300" FontSize="11" Margin="12,0,20,38" ItemsSource="{Binding Source={StaticResource listedView}, Path=myItemsSource, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<ListBox.ItemTemplate >
<DataTemplate>
<Border BorderBrush="Blue" Margin="0,4,0,4" BorderThickness="1" CornerRadius="5">
<StackPanel Orientation="Horizontal">
<Label Content="Show rules where:" Name="lblshowrules"></Label>
<ComboBox x:Name="cboShowRuleWhere" Height="20" Width="200" ItemsSource="{Binding Source={StaticResource listedView}, Path=FilterRules}" DisplayMemberPath="RuleName" SelectedValuePath="RuleId" SelectedValue="{Binding Source={StaticResource listedView}, Path=SelectedRuleName, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ></ComboBox>
<Grid Height="29" HorizontalAlignment="Left" Name="grid1" VerticalAlignment="Top" Width="496" Grid.Row="1" Margin="0,0,0,0">
<ComboBox Height="21" HorizontalAlignment="Left" Margin="6,4,0,0" x:Name="cboRuleCondtion" VerticalAlignment="Top" Width="212" />
<TextBox Height="20" HorizontalAlignment="Left" Margin="242,3,0,0" x:Name="txtValue" VerticalAlignment="Top" Width="245" Visibility="Hidden"/>
<ComboBox Height="21" HorizontalAlignment="Left" Margin="224,3,0,0" x:Name="cboValue" VerticalAlignment="Top" Width="205" Visibility="Hidden" />
<DatePicker Height="28" HorizontalAlignment="Left" Margin="242,-3,0,0" x:Name="dtpFromDate" VerticalAlignment="Top" Width="98" Visibility="Hidden" />
<DatePicker Height="31" HorizontalAlignment="Left" Margin="346,-3,0,0" x:Name="dtpToDate" VerticalAlignment="Top" Width="98" Visibility="Hidden"/>
</Grid>
<Button Name="cmdAddLevel" Padding="0" Margin="-1,1,0,-1" Width="75" Command ="{Binding Source={StaticResource listedView}, Path=AddLevelCommand, UpdateSourceTrigger=PropertyChanged}" BorderBrush="White" BorderThickness="1" Height="25" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<Image Height="16" Width="16" HorizontalAlignment="Left" Margin="1,0,0,-1">
</Image>
<TextBlock Text="Add Level" FontWeight="Bold" Height="16" Width="70" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="8,2,0,-1" />
</StackPanel>
</Button>
<Label Name="lblDeleteLevel" Margin="3,0,0,0" Width="75" TabIndex="7" HorizontalAlignment="Left">
<Hyperlink >
<TextBlock Text="Delete Level" />
</Hyperlink>
</Label>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Please help me. once again, i want to know how to get the child control from parent control... Is it possible?
Using the MVVM pattern, you should not be referencing any of the controls directly. Alternatively, you should create a boolean property on your viewmodel that decides if various controls should be visible. Then bind the Visibility property of the controls you want to hide to this property, using a converter.
See this previous Q/A for details on visibility converters: Link
I'm having a little trouble in silverlight with a databound ListBox containing databound TextBox elements. The items display correctly in the list and the TextBox is populated correctly but I can't get focus on the TextBox in the list. If I hover over the edges of the TextBox it highlights but it won't let me click into it to edit the text. Any ideas?
My XAML looks like this:
<ListBox x:Name="listImages">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="LayoutRoot" Background="White">
<Image Height="102" HorizontalAlignment="Left" Name="imgThumb" Stretch="UniformToFill" VerticalAlignment="Top" Width="155" Source="{Binding ImageFilename, Converter={StaticResource ImageConverter}}" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="154,25,0,0" Name="txtAltText" VerticalAlignment="Top" Width="239" Text="{Binding Alt}" />
<dataInput:Label Height="19" HorizontalAlignment="Left" Margin="154,6,0,0" Name="lblAltText" VerticalAlignment="Top" Width="239" Content="Alt Text" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I swapped the content for this and it now works, I think it was having an issue with the Grid container:
<ListBox x:Name="listImages">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Height="102" HorizontalAlignment="Left" Name="imgThumb" Stretch="UniformToFill" VerticalAlignment="Top" Width="155" Source="{Binding ImageFilename, Converter={StaticResource ImageConverter}}" Margin="5" />
<StackPanel>
<dataInput:Label Height="19" HorizontalAlignment="Left" Name="lblAltText" VerticalAlignment="Top" Width="239" Content="Alt Text" />
<TextBox Height="23" HorizontalAlignment="Stretch" Name="txtAltText" VerticalAlignment="Top" Text="{Binding Alt}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>