I have a problem with the intellisense. It works in code behind but not in xaml code (wpf).
1st image: Intelissense not working
2nd image: I comment on the 1st usercontrol and the intellisense works.
Here the code is in the usercontrol "cuAccessoiresAutres":
<UserControl x:Class="MicroSecu.ControleUtilisateur.cuAccessoiresAutres"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ControleUtilisateur="clr-namespace:MicroSecu.ControleUtilisateur"
mc:Ignorable="d"
d:DesignHeight="251" d:DesignWidth="672">
<UserControl.Resources>
<SolidColorBrush x:Key="controlBorderBrush" Color="LightGray" />
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<!--En tête-->
<Border Grid.Row="0" Grid.Column="0" BorderThickness="0,0,1,1" BorderBrush="{StaticResource controlBorderBrush}"></Border>
<Border Grid.Row="0" Grid.Column="1" BorderThickness="1,2,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Gauche" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16" FontWeight="Bold"></TextBlock>
</Border>
<Border Grid.Row="0" Grid.Column="2" BorderThickness="1,2,2,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Droit" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16" FontWeight="Bold"></TextBlock>
</Border>
<!--Profil porteur-->
<Border Grid.Row="1" Grid.Column="0" BorderThickness="2,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Profil porteur" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="12" TextWrapping="Wrap"></TextBlock>
</Border>
<Border Grid.Row="1" Grid.Column="1" BorderThickness="1,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.ProfilPorteurGauche}" IsEnabled="{Binding MaConsole.ProfilPorteurGaucheEstDispo}"></CheckBox>
</Border>
<Border Grid.Row="1" Grid.Column="2" BorderThickness="1,1,2,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.ProfilPorteurDroit}" IsEnabled="{Binding MaConsole.ProfilPorteurDroitEstDispo}"></CheckBox>
</Border>
<!--Anneau décalé-->
<Border Grid.Row="2" Grid.Column="0" BorderThickness="2,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Anneau décalé" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="12" TextWrapping="Wrap"></TextBlock>
</Border>
<Border Grid.Row="2" Grid.Column="1" BorderThickness="1,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.AnneauDécaléGauche}" IsEnabled="{Binding MaConsole.AnneauDécaléGaucheEstDispo}"></CheckBox>
</Border>
<Border Grid.Row="2" Grid.Column="2" BorderThickness="1,1,2,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.AnneauDécaléDroit}" IsEnabled="{Binding MaConsole.AnneauDécaléDroitEstDispo}"></CheckBox>
</Border>
<!--Glissière de reprise-->
<Border Grid.Row="3" Grid.Column="0" BorderThickness="2,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Glissière de reprise" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap"></TextBlock>
</Border>
<Border Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" BorderThickness="1,1,2,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.GlissièreDeReprise}" IsEnabled="{Binding MaConsole.GlissièreDeRepriseEstDispo}"></CheckBox>
</Border>
<!--Glissière de reprise plateau arrière-->
<Border Grid.Row="4" Grid.Column="0" BorderThickness="2,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Glissière de reprise plateau arrière" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap"></TextBlock>
</Border>
<Border Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" BorderThickness="1,1,2,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.GlissièreDeReprisePlateauArrière}" IsEnabled="{Binding MaConsole.GlissièreDeReprisePlateauArrièreEstDispo}"></CheckBox>
</Border>
<!--Tôle sur extensible-->
<Border Grid.Row="5" Grid.Column="0" BorderThickness="2,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Tôle sur extensible" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap"></TextBlock>
</Border>
<Border Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" BorderThickness="1,1,2,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.TôleSurExtensible}" IsEnabled="{Binding MaConsole.TôleSurExtensibleEstDispo}"></CheckBox>
</Border>
<!--Plaque verte RMTCE-->
<Border Grid.Row="6" Grid.Column="0" BorderThickness="2,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Plaque verte RMTCE" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap"></TextBlock>
</Border>
<Border Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2" BorderThickness="1,1,2,1" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.PlaqueVerteRMTCE}" IsEnabled="{Binding MaConsole.PlaqueVerteRMTCEEstDispo}"></CheckBox>
</Border>
<!--Plaque jaune benne 1000L-->
<Border Grid.Row="7" Grid.Column="0" BorderThickness="2,1,1,1" BorderBrush="{StaticResource controlBorderBrush}">
<TextBlock Text="Plaque jaune benne 1000L" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap"></TextBlock>
</Border>
<Border Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="2" BorderThickness="1,1,2,2" BorderBrush="{StaticResource controlBorderBrush}">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding MaConsole.PlaqueJaune1000L}" IsEnabled="{Binding MaConsole.PlaqueJaune1000LEstDispo}"></CheckBox>
</Border>
</Grid>
Related
I'm trying to using DataTemplates and Styles with DataTriggers to simplify my code and I'm having difficulty figuring out how to properly set up the binding. I keep staring at this and just feel 'stuck' with where to go next.
The DataTemplate will be applied to the items in a ListView, and the items themselves will be a [5,5] array of booleans. I'm merely trying to display these items where the border background is red if true, and white if false.
Am I going down the wrong path entirely and should be utilizing a UserControl?
<Style x:Key="BingoCell" TargetType="Border">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="BingoRulesTemplate">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Grid.Column="0" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="0" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="0" Grid.Column="2" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="0" Grid.Column="3" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="0" Grid.Column="4" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="1" Grid.Column="0" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="1" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="1" Grid.Column="2" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="1" Grid.Column="3" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="1" Grid.Column="4" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="2" Grid.Column="0" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="2" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="2" Grid.Column="2" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="2" Grid.Column="3" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="2" Grid.Column="4" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="3" Grid.Column="0" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="3" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="3" Grid.Column="2" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="3" Grid.Column="3" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="3" Grid.Column="4" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="4" Grid.Column="0" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="4" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="4" Grid.Column="2" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="4" Grid.Column="3" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
<Border Grid.Row="4" Grid.Column="4" BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}"/>
</Grid>
</DataTemplate>
You can bind to a specific position in a jagged array using the following syntax:
<DataTrigger Binding="{Binding [0][0]}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
Unfortunately this means that you will need a separate Style with a separate Trigger for each bool in the array(s). There is no way to dynamically replace just the binding path in a template but keep the rest. XAML doesn't support this.
One option would be to create the styles/templates programmatically, for example using the XamlReader.Parse method.
Or replace the jagged array with a view model class that has a property that can be used to determine the background colour of the Border in the template.
Thanks to #Clemens and #Andy I was able to find a solution using a pair of nested ItemsControl that worked for me. I did have to flatten the 5x5 array of bools.
<ItemsControl x:Name="ExamplePatterns" Grid.Row="1" ItemsSource="{Binding GameRules.ExamplePatterns}" HorizontalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding BoolsFlat}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Margin="10" Columns="5" Background="Azure"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness="1" Style="{StaticResource BingoCell}">
<TextBlock Text="" Height="Auto" Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I've a grid with 3 rows.When I drag down to grid splitter,the grid splitter disappeared.But I need to do "auto" height of the first row.How can I fix this problem?
Here is code:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="20"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel>
<Border Background="BlueViolet" Height="20" Margin="3"/>
<Border Background="BlueViolet" Height="20" Margin="3"/>
<Border Background="BlueViolet" Height="20" Margin="3"/>
<Border Background="BlueViolet" Height="20" Margin="3"/>
<Border Background="BlueViolet" Height="20" Margin="3"/>
</StackPanel>
<GridSplitter Background="White" HorizontalAlignment="Stretch" Grid.Row="1" Height="5"/>
<TextBlock IsHitTestVisible="False" Text="GridSplitter here.." Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Border Background="CornflowerBlue" Grid.Row="2" Margin="3"/>
</Grid>
Thanks for your help.
Have moved on to teaching myself WPF, rather than continuing along with winforms. I haven't gotten into the more detailed aspects of binding yet, trying to get my first run interface done beforehand so I have a better grasp of how the xaml and code behind file works together. Anyway, I'm trying to build a table with four rows of inputs, each of 11 columns, with the 11th column being combo boxes. All other inputs are text boxes. the code below produces a table with borders all of thickness 2. However, for reasons I can't figure out, it also produces a gap between the 3rd and 4th row, when all the xaml definitions are the same.
Any help that can be provided is greatly appreciated, and I apologize for the crude code - tidying up is high on the agenda.
Note 1; this grid lives in another grid. The parent row definition is set to auto
Note 2; If I extend the page design beyond this grid in the designer, it is rendered fine at design time, but the gap appears when entering debug.
Note 3; I copied the code into another instance of VS2012, and it seems to work fine both in design and debug....
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="30"/>
<ColumnDefinition MinWidth="75"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Label Grid.Column="0" FontWeight="Bold" BorderBrush="Black" BorderThickness="2,2,1,1">A</Label>
<Label Grid.Column="1" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">B</Label>
<Label Grid.Column="2" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">C</Label>
<Label Grid.Column="3" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">D</Label>
<Label Grid.Column="4" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">E</Label>
<Label Grid.Column="5" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">F</Label>
<Label Grid.Column="6" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">G</Label>
<Label Grid.Column="7" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">H</Label>
<Label Grid.Column="8" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">I</Label>
<Label Grid.Column="9" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,1,1" HorizontalContentAlignment="Center">J</Label>
<Label Grid.Column="10" FontWeight="Bold" BorderBrush="Black" BorderThickness="1,2,2,1" HorizontalContentAlignment="Center">K</Label>
<TextBox Grid.Column="0" Grid.Row="1" BorderBrush="Black" BorderThickness="2,1,1,1" Padding="1" MinWidth="150"/>
<TextBox Grid.Column="1" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="2" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="3" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="4" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="5" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="6" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="7" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="8" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="9" Grid.Row="1" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<ComboBox Grid.Column="10" Grid.Row="1">
<!--Combobox items-->
</Combobox>
<TextBox Grid.Column="0" Grid.Row="2" BorderBrush="Black" BorderThickness="2,1,1,1" Padding="1" MinWidth="150"/>
<TextBox Grid.Column="1" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="2" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="3" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="4" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="5" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="6" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="7" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="8" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<TextBox Grid.Column="9" Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="1"/>
<ComboBox Grid.Column="10" Grid.Row="2">
<!-- Combobox items -->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="3" BorderBrush="Black" BorderThickness="2,1,1,1" Padding="1" MinWidth="150" Visibility="Visible"/>
<TextBox Grid.Column="1" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="2" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="3" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="4" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="5" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="6" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="7" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="8" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<TextBox Grid.Column="9" Grid.Row="3" BorderBrush="Black" BorderThickness="1" Padding="1" Visibility="Visible"/>
<ComboBox Grid.Column="10" Grid.Row="3" Visibility="Visible">
<!-- Combobox items -->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="4" BorderBrush="Black" BorderThickness="2,1,1,2" Padding="1" MinWidth="150"/>
<TextBox Grid.Column="1" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="2" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="3" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="4" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="5" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="6" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="7" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="8" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<TextBox Grid.Column="9" Grid.Row="4" BorderBrush="Black" BorderThickness="1,1,1,2" Padding="1"/>
<ComboBox Grid.Column="10" Grid.Row="4">
<!-- Combobox items -->
</ComboBox>
</Grid>
i used a GroupBox with a scrollviewer inside it ..and inside scrollviewer i put a grid and begin to put my controls (3 textblocks and 7 textboxes)
i can't make scrollviewer to scroll my content ..and i don't know if i miss something to activate it
here is my xaml code:
<GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Margin="363,20,38,486" Name="groupBox1" VerticalAlignment="Stretch" Panel.ZIndex="0">
<ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto" ScrollChanged="scrollViewer1_ScrollChanged" VerticalScrollBarVisibility="Auto" >
<Grid Name="grid1" Height="132">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock1" Text="Generic ID" VerticalAlignment="Center" FontSize="14" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock2" Text="Generic Name" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock3" Text="Other Names" VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox1" VerticalAlignment="Center" Width="197" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox2" VerticalAlignment="Center" Width="197" Grid.Row="1" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox3" VerticalAlignment="Center" Width="197" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox4" VerticalAlignment="Center" Width="197" Grid.Row="3" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox5" VerticalAlignment="Center" Width="197" Grid.Row="4" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox6" VerticalAlignment="Center" Width="197" Grid.Row="5" Padding="0" />
</Grid>
</ScrollViewer>
</GroupBox>
Try setting your GroupBox's Height. It is stretching to fill the entire Window and your content is stretching to Fit. If you limit the size of the GroupBox you will get your VerticalScroll and it will work. I modified your code to this and it works:
<GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Height="132" Name="groupBox1" Panel.ZIndex="0">
<ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto" ScrollChanged="scrollViewer1_ScrollChanged" VerticalScrollBarVisibility="Auto" >
<Grid Name="grid1" Height="132">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Grid.RowSpan="1" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock1" Text="Generic ID" VerticalAlignment="Center" FontSize="14" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock2" Text="Generic Name" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Padding="0" />
<TextBlock FontSize="14" Height="Auto" HorizontalAlignment="Right" Margin="0" Name="textBlock3" Text="Other Names" VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox1" VerticalAlignment="Center" Width="197" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox2" VerticalAlignment="Center" Width="197" Grid.Row="1" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox3" VerticalAlignment="Center" Width="197" Grid.Row="2" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox4" VerticalAlignment="Center" Width="197" Grid.Row="3" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox5" VerticalAlignment="Center" Width="197" Grid.Row="4" Padding="0" />
<TextBox Height="23" HorizontalAlignment="Center" Margin="0" Name="textBox6" VerticalAlignment="Center" Width="197" Grid.Row="5" Padding="0" />
</Grid>
</ScrollViewer>
</GroupBox>
With the result of this:
I modified your code a bit
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<GroupBox BorderBrush="#FF0000DD" FontSize="13" FontWeight="Bold" Header="General Information" HorizontalAlignment="Stretch" Margin="1,0,0,129" Name="groupBox1" VerticalAlignment="Stretch" Grid.Column="1" Grid.RowSpan="3">
<ScrollViewer Name="scrollViewer1" Width="Auto" VerticalScrollBarVisibility="Visible" >
<Grid Name="grid1" Width="376" Height="280">
<TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto" Name="textBlock4" Padding="0" Text="Generic ID" TextAlignment="Right" Margin="-20,0,20,0" />
<TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto" Name="textBlock5" Padding="0" Text="Generic Name" TextAlignment="Right" Margin="-10,20,10,-20" />
<TextBlock FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" Height="Auto" Name="textBlock6" Padding="0" Text="Other Names" TextAlignment="Right" Margin="-15,43,15,-43" />
<TextBox Height="25" Name="textBox8" Width="225" Margin="22,199,130,44" />
<TextBox Height="25" Name="textBox9" Width="225" Margin="20,147,131,95" />
<TextBox Height="25" Name="textBox11" Width="225" Margin="20,97,131,159" />
<TextBox Height="25" Name="textBox12" Margin="21,122,131,121" />
<TextBox Height="25" Name="textBox13" Width="225" Margin="20,159,131,52" />
<TextBox Height="25" Name="textBox14" Width="225" Margin="20,222,131,20" />
</Grid>
</ScrollViewer>
</GroupBox>
</Grid>
Just try whether this works out.I think the margin and height are resulting in the problem
I'm learning WPF and the MVVM Pattern and I'm trying to build a calendar-like view.
So I currently have a Grid with 6 rows and 7 columns.
The first row should be the Header, thus specifying the Week days like 'Monday, Tuesday, etc...'
I have the following right now in my MonthView.xaml
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding RowHeight}"/>
<RowDefinition Height="{Binding RowHeight}"/>
<RowDefinition Height="{Binding RowHeight}"/>
<RowDefinition Height="{Binding RowHeight}"/>
<RowDefinition Height="{Binding RowHeight}"/>
<RowDefinition Height="{Binding RowHeight}"/>
<RowDefinition Height="{Binding RowHeight}"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding CellWidth}"/>
<ColumnDefinition Width="{Binding CellWidth}"/>
<ColumnDefinition Width="{Binding CellWidth}"/>
<ColumnDefinition Width="{Binding CellWidth}"/>
<ColumnDefinition Width="{Binding CellWidth}"/>
<ColumnDefinition Width="{Binding CellWidth}"/>
<ColumnDefinition Width="{Binding CellWidth}"/>
</Grid.ColumnDefinitions>
<!-- Header Row-->
<ContentPresenter Grid.Row="0" Grid.Column="0">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding DaysOfWeek[0]}"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
<ContentPresenter ContentTemplate="{StaticResource CalendarHeaderCellTemplate}" Grid.Row="0" Grid.Column="1" DataContext="{Binding DaysOfWeek[1]}"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarHeaderCellTemplate}" Grid.Row="0" Grid.Column="2" DataContext="{Binding DaysOfWeek[2]}"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarHeaderCellTemplate}" Grid.Row="0" Grid.Column="3" DataContext="{Binding DaysOfWeek[3]}"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarHeaderCellTemplate}" Grid.Row="0" Grid.Column="4" DataContext="{Binding DaysOfWeek[4]}"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarHeaderCellTemplate}" Grid.Row="0" Grid.Column="5" DataContext="{Binding DaysOfWeek[5]}"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarHeaderCellTemplate}" Grid.Row="0" Grid.Column="6" DataContext="{Binding DaysOfWeek[6]}"/>
<!-- 1st Row-->
<ContentPresenter ContentTemplate="{StaticResource CalendarCellTemplate}" Grid.Row="1" Grid.Column="0"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarCellTemplate}" Grid.Row="1" Grid.Column="1"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarCellTemplate}" Grid.Row="1" Grid.Column="2"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarCellTemplate}" Grid.Row="1" Grid.Column="3"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarCellTemplate}" Grid.Row="1" Grid.Column="4"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarCellTemplate}" Grid.Row="1" Grid.Column="5"/>
<ContentPresenter ContentTemplate="{StaticResource CalendarCellTemplate}" Grid.Row="1" Grid.Column="6"/>
On so on: You see the pattern I guess.
Here's the CalendarHeaderCellTemplate
<DataTemplate x:Key="CalendarHeaderCellTemplate">
<StackPanel Margin="5" Background="Blue">
<TextBlock Text="{Binding}"></TextBlock>
</StackPanel>
</DataTemplate>
And here's the important parts of the ViewModel:
public ObservableCollection<string> DaysOfWeek { get; private set; }
public MonthViewModel()
{
this.DaysOfWeek = new ObservableCollection<string> {DayOfWeek.Monday.ToString(), DayOfWeek.Tuesday.ToString(), DayOfWeek.Wednesday.ToString(),
DayOfWeek.Thursday.ToString(), DayOfWeek.Friday.ToString(), DayOfWeek.Saturday.ToString(), DayOfWeek.Sunday.ToString()};
}
Now neither the Contentpresenter where I define the DataTemplate 'inline' does display anything inside its TextBlock nor the CalendarHeaderCellTemplate.
Funny thing is, inside the Visual Studio designer, everything show up correctly, except for the first cell (i.e. the one with the inline template)
Does anyone have a suggestion.
N.B. The 'inline' template was mostly done for testing purposes.
EDIT:
Doing this (see below) instead of using the ContentPresenter works fine. Maybe I use the ContentPresenter in a wrong manner?
<StackPanel Grid.Row="0" Grid.Column="0">
<TextBlock Text="{Binding DaysOfWeek[0]}"/>
</StackPanel>
The reason I want to use a ContentPresenter is because the DataTemplate for the content of every cell is going to be much more than just a textbox in the end.
Try changing your ContentPresenter to
<ContentPresenter Content="{Binding DaysOfWeek[0]}" Grid.Row="0" Grid.Column="0">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
or
<ContentPresenter Content="{Binding}" Grid.Row="0" Grid.Column="0">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding DaysOfWeek[0]}"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
and also replace your DataContext with Content like
<ContentPresenter ContentTemplate="{StaticResource CalendarHeaderCellTemplate}" Grid.Row="0" Grid.Column="1" Content="{Binding DaysOfWeek[1]}"/>
try using ContentControl rather than ContentPresenter
<Style x:Key="CalendarCell" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<StackPanel Margin="5" Background="{TemplateBinding Background}">
<TextBlock Text="{TemplateBinding Content}"
Foreground="{TemplateBinding Foreground}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Header Row-->
<ContentControl Style="{StaticResource CalendarCell}"
Content="{Binding DaysOfWeek[0]}"
Background="Blue"
Foreground="White" />
<ContentControl Style="{StaticResource CalendarCell}"
Content="{Binding DaysOfWeek[1]}"
Background="Blue"
Foreground="White"
Grid.Column="1" />
<ContentControl Style="{StaticResource CalendarCell}"
Content="{Binding DaysOfWeek[2]}"
Background="Blue"
Foreground="White"
Grid.Column="2" />
<ContentControl Style="{StaticResource CalendarCell}"
Content="{Binding DaysOfWeek[3]}"
Background="Blue"
Foreground="White"
Grid.Column="3" />
<ContentControl Style="{StaticResource CalendarCell}"
Content="{Binding DaysOfWeek[4]}"
Background="Blue"
Foreground="White"
Grid.Column="4" />
<ContentControl Style="{StaticResource CalendarCell}"
Content="{Binding DaysOfWeek[5]}"
Background="Blue"
Foreground="White"
Grid.Column="5" />
<ContentControl Style="{StaticResource CalendarCell}"
Content="{Binding DaysOfWeek[6]}"
Background="Blue"
Foreground="White"
Grid.Column="6" />
<!-- 1st Row-->
<ContentControl Style="{StaticResource CalendarCell}"
Content=""
Background="Wheat"
Foreground="Black"
Grid.Row="1" />
<ContentControl Style="{StaticResource CalendarCell}"
Content=""
Background="Wheat"
Foreground="Black"
Grid.Column="1"
Grid.Row="1" />
<ContentControl Style="{StaticResource CalendarCell}"
Content=""
Background="Wheat"
Foreground="Black"
Grid.Column="2"
Grid.Row="1" />
<ContentControl Style="{StaticResource CalendarCell}"
Content=""
Background="Wheat"
Foreground="Black"
Grid.Column="3"
Grid.Row="1" />
<ContentControl Style="{StaticResource CalendarCell}"
Content=""
Background="Wheat"
Foreground="Black"
Grid.Column="4"
Grid.Row="1" />
<ContentControl Style="{StaticResource CalendarCell}"
Content=""
Background="Wheat"
Foreground="Black"
Grid.Column="5"
Grid.Row="1" />
<ContentControl Style="{StaticResource CalendarCell}"
Content=""
Background="Wheat"
Foreground="Black"
Grid.Column="6"
Grid.Row="1" />