Scrollviewer visibility after debugging - c#

I have a WPF Application. I added a scrollviewer to a window. However I can see the scrollviewer during the design. When I debug the project then the scrollviewer does not seem...
There is the code
</local:WorkControl.DataContext>
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Grid Name="mainGrid" VerticalAlignment="Top">
<Grid.Background>
<ImageBrush Stretch="Fill" TileMode="FlipXY" Viewport="0,0,1479,437" ViewportUnits="Absolute" />
</Grid.Background>
<DockPanel HorizontalAlignment="Stretch" Margin="1,1,1,1" Name="dockPanel1" VerticalAlignment="Top" Width="Auto">
<Grid Name="grid1" Width="Auto" Margin="0" VerticalAlignment="Top" DockPanel.Dock="Top" OpacityMask="Black" ShowGridLines="False" OverridesDefaultStyle="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="250" />
<ColumnDefinition Width="310" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="123" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Grid.ColumnSpan="3" BorderBrush="Silver" BorderThickness="1" HorizontalAlignment="Left" Margin="2" Name="borAdrTopR" VerticalAlignment="Top" CornerRadius="5"
AllowDrop="False">
<Canvas Width="834" Height="40" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" Name="panelTop" ContextMenuOpening="panelTop_ContextMenuOpening">
<TextBlock Name="txAdrID" Canvas.Left="11" Canvas.Top="11" Height="20" Text="AdrID:" Width="44" Foreground="Silver" FontWeight="Bold" />
<TextBox Text="{Binding [AdrID]}" Height="20" HorizontalAlignment="Right" Margin="0,11,602,0" Name="tbAdrID" Width="86" VerticalAlignment="Top" FontWeight="Bold"
VerticalContentAlignment="Top" Foreground="Silver" Canvas.Left="54" Canvas.Top="-1" Padding="1" BorderThickness="0" IsReadOnly="True" Background="{x:Null}" />
<TextBlock Canvas.Left="488" Canvas.Top="11" Height="20" Text="Adresspool:" Width="70" TextAlignment="Right" />
<CheckBox Canvas.Left="570" Canvas.Top="11" Content="MSS" Height="16" Name="chkMSSPool" Checked="chkPool_Checked" Unchecked="chkPool_Checked" />
<CheckBox Canvas.Left="620" Canvas.Top="11" Content="GMM" Height="16" Name="chkGMMPool" Checked="chkPool_Checked" Unchecked="chkPool_Checked" />
<CheckBox Canvas.Left="675" Canvas.Top="11" Content="MZ" Height="16" Name="chkMZPool" Checked="chkPool_Checked" Unchecked="chkPool_Checked" IsEnabled="False" />
<CheckBox Canvas.Left="728" Canvas.Top="11" Content="Sage" Height="16" Name="chkSagePool" Checked="chkPool_Checked" Unchecked="chkPool_Checked" />
<CheckBox Canvas.Left="780" Canvas.Top="11" Content="Web" Height="16" Name="chkMyMalikPool" IsEnabled="False" Checked="chkPool_Checked" Unchecked="chkPool_Checked" />
<TextBox Background="{x:Null}" BorderThickness="0" Canvas.Left="367" Canvas.Top="9" FontWeight="Bold" Foreground="Red" Height="21" IsReadOnly="True" Name="tbSecInfo"
Padding="1" Text="" VerticalContentAlignment="Top" Width="101" />
<Image Canvas.Left="268" Canvas.Top="11" Height="16" Name="imgCRMstatus" Stretch="None" Width="96" MouseLeftButtonUp="imgCRMstatus_MouseClick"
MouseRightButtonUp="imgCRMstatus_MouseClick" />
<Label Canvas.Left="257" Canvas.Top="17" Height="11" Name="lbCRMStatus" Width="9" IsEnabled="False" />
<Image Canvas.Left="466" Canvas.Top="7" Height="24" Name="imgSec" Stretch="None" Width="24" MouseRightButtonUp="imgSec_MouseClick" MouseLeftButtonUp="imgSec_MouseClick"
Visibility="Hidden" />
</Canvas>
</Border>
<Border Grid.Row="1" BorderBrush="Silver" BorderThickness="1" HorizontalAlignment="Left" Name="borAddress" VerticalAlignment="Top" CornerRadius="5" Background="White"
AllowDrop="False">
<FlowDocumentScrollViewer HorizontalAlignment="Left" Name="fdocview" VerticalAlignment="Top" Height="Auto" VerticalScrollBarVisibility="Auto" Background="#FFFFFFF9"
Margin="2" HorizontalContentAlignment="Left" Padding="0" MinHeight="118">
<FlowDocument TextAlignment="Left" FontSize="12" PagePadding="5">
<FlowDocument.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="FontSize" Value="13" />
<Setter Property="Foreground" Value="DarkBlue" />
<Setter Property="FontFamily" Value="Trebuchet MS" />
<Setter Property="Margin" Value="0,0,0,0" />
</Style>
</FlowDocument.Resources>
<Paragraph>ViewControl...mmm</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
</Border>
<Border Grid.Row="1" Grid.Column="1" BorderBrush="Silver" BorderThickness="1" Padding="3" Name="borAdrInfoLeft" CornerRadius="6" AllowDrop="False">
<Grid VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="73" />
<ColumnDefinition />
<ColumnDefinition Width="35" />
<ColumnDefinition Width="45" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<local:ComboBoxCW Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" x:Name="cbAdrTypeID" CWListName="Adresstypen" Background="#FFC8D2E8"
SelectedID="{Binding Path=[AdrTypeID]}" SelectionChanged="cwAdrType_SelectionChanged" Margin="0,0,0,3" />
<local:ComboBoxCW Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="3" x:Name="cbGruppenID" SelectedID="{Binding [GruppenID]}" CWListName="Gruppen" Background="#FFC8D2E8"
CWListArt="withall" CWListFilter="M" Margin="0,0,0,3" />
<TextBlock Grid.Column="3" Grid.Row="0" Name="txtBedeutung" Text="$$" Width="22" TextAlignment="Center" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="2" Name="tbKundenNr" Canvas.Left="83" Text="{Binding [KundenNr]}" BorderBrush="#96000000" MaxLength="30" Margin="0,0,0,3" />
<TextBox Grid.Column="3" Grid.Row="2" Name="tbCRA" Text="{Binding [CRA]}" BorderBrush="#96000000" IsReadOnly="True" Margin="0,0,0,3" />
<local:ComboBoxCW Grid.Column="1" Grid.Row="3" x:Name="cwSprachID" SelectedID="{Binding [SprachID],Mode=TwoWay}" CWListName="Sprachen" CWListArt="withempty"
Margin="0,0,0,3" />
<ComboBox Grid.Column="3" Grid.Row="3" Name="cbBedeutung" Text="{Binding Path=[Bedeutung]}">
<ComboBoxItem Content=" " />
<ComboBoxItem Content="A" />
<ComboBoxItem Content="B" />
<ComboBoxItem Content="C" />
</ComboBox>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Adressart" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="Gruppe" />
<TextBlock Grid.Column="0" Grid.Row="2" Text="Kundennr." />
<TextBlock Grid.Column="2" Grid.Row="2" Text="CRA" TextAlignment="Right" />
<TextBlock Grid.Column="0" Grid.Row="3" Text="Sprache" />
<TextBlock Grid.Column="2" Grid.Row="3" Text="Bed." TextAlignment="Right" />
</Grid>
</Border>
<Border Grid.Row="1" Grid.Column="2" BorderBrush="Silver" BorderThickness="1" Padding="3" Name="borAdrInfoRight" CornerRadius="6" AllowDrop="False">
<Grid VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="73" />
<ColumnDefinition />
<ColumnDefinition Width="35" />
<ColumnDefinition Width="30" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<local:ComboBoxCW Grid.Row="0" Grid.Column="1" x:Name="cbAdrStatusID" SelectedID="{Binding [AdrStatusID]}" CWListName="Adressstati" Margin="0,0,0,3"
Background="#FFC8D2E8" />
<TextBox Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" Name="tbMZunitID"
Text="{Binding [MZunitID],Mode=OneWay,Converter={StaticResource codetextfromid}, ConverterParameter=MZunits}" Margin="0,0,0,3" BorderBrush="#96000000"
IsReadOnly="True" />
<local:ComboBoxCW Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" x:Name="cbBetreuerID" Text="" Background="#FFC8D2E8" CWListName="Mitarbeiter" Margin="0,0,0,3"
SelectedID="{Binding Path=[BetreuerID]}" CWListArt="withall" />
<ListBox Grid.Row="2" Grid.Column="1" Name="listBetreuers" BorderBrush="#96000000" SelectionChanged="listBetreuers_SelectionChanged" Grid.ColumnSpan="3"
Grid.RowSpan="2" Margin="0,0,0,3" />
<Popup Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" OpacityMask="#00000000" Name="popAdd" StaysOpen="False" PlacementTarget="{Binding ElementName=listBetreuers}"
Placement="Bottom" HorizontalOffset="-40" VerticalOffset="-20">
<ListBox Height="160" Width="270" HorizontalAlignment="Left" Name="listAdd" VerticalAlignment="Top" SelectionChanged="listAdd_SelectionChanged" />
</Popup>
<Button Grid.Row="3" Grid.Column="4" Content="-" Height="22" Width="22" Name="btnBetreuerDel" Click="btnBetreuerDel_Click" HorizontalAlignment="Right" />
<Button Grid.Row="2" Grid.Column="4" Content="+" Height="22" Width="22" Name="btnBetreuerAdd" Click="btnBetreuerAdd_Click" HorizontalAlignment="Right" />
<Button Grid.Row="1" Grid.Column="4" Content="H" Height="22" Width="22" Name="btnBetreuerHaupt" Click="btnBetreuerHaupt_Click" HorizontalAlignment="Right" />
<TextBlock Grid.Row="0" Grid.Column="0" Text="Status" />
<TextBlock Grid.Row="0" Grid.Column="2" Text="Unit" TextAlignment="Right" Margin="2" />
<TextBlock Name="lbHauptbetrP" Visibility="Visible" Grid.Row="1" Grid.Column="0" Text="Hauptbetr." />
<TextBlock Name="lbHauptbetrF" Visibility="Hidden" Grid.Row="1" Grid.Column="0" Text="Account-Mgr." />
<TextBlock Grid.Row="2" Grid.Column="0" Text="weitere Betreuer" TextWrapping="Wrap" />
</Grid>
</Border>
<!-- ====TAB Firma start -->
<TabControl Grid.Row="2" Grid.ColumnSpan="3" Name="tabReg" Margin="0" SelectionChanged="tabReg_SelectionChanged" VerticalAlignment="Stretch" Padding="2,2">
<TabItem Header="Firma" Name="regFirma" local:HelpProvider.HelpParameter="AddressControl;Firma">
<Grid VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<!-- ====Firmen-Felder linke Seite -->
<Border Grid.Row="0" Grid.Column="0" BorderBrush="Silver" BorderThickness="1" Padding="3" Name="borFeed0" CornerRadius="6" AllowDrop="False">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="95" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="35" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="38" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Firma" />
<Button Name="btnLinkFirma" Height="23" Width="23" ToolTip="Mit Firma verknüpfen..." Click="btnLinkFirma_Click" Grid.Column="0" Grid.Row="0"
HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,5,0">
<Button.Content>
<Image Source="Images/Verknuepfung_32.png" />
</Button.Content>
</Button>
<TextBox Name="tbFirma" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Margin="0,0,0,3" Text="{Binding Path=[Firma]}" BorderBrush="#96000000"
MouseDoubleClick="tbFirma_MouseDoubleClick" MaxLength="80" AcceptsReturn="True" />
<TextBox x:Name="tbFirmazusatz" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" Margin="0,0,0,3" Text="{Binding Path=[Firmazusatz]}" BorderBrush="#96000000"
MaxLength="50" />
There are more codes

Adding to Aghilas's answer
If you have set HorizontalScrollBarVisibility, VerticalScrollBarVisibility properties to 'Auto', try setting them to Visible.

Related

Divide first row in the grid to four equal parts WPF

I used to draw something like tabcontrol in WizardPage control of extended WPF toolkit.
Relevant xaml code:
<xctk:WizardPage x:Name="Page1" PageType="Blank" Width="540"
BorderBrush="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="200"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<TextBox Width="135" Text="Step 1" Background="#FF2BADDE" FontSize="16" TextAlignment="Center" />
<TextBox Width="135" Text="Step 2" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
<TextBox Width="135" Text="Step 3" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
<TextBox Width="135" Text="Step 4" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
</DockPanel>
<Grid Grid.Row="1">
<GroupBox Header="Group 1" FontSize="16" Height="80" Margin="0,0,0,90" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="270"/>
<ColumnDefinition Width="270"/>
</Grid.ColumnDefinitions>
<RadioButton x:Name="RadioButNew" Content="New" FontSize="13.333" BorderThickness="0,1,1,1" HorizontalAlignment="Left" Margin="30,30,0,0"/>
<RadioButton x:Name="RadioButUpdate" Content="Update" Grid.Column="1" FontSize="13.333" Focusable="False" HorizontalAlignment="Left" Margin="30,30,0,0"/>
</Grid>
</GroupBox>
</Grid>
But text boxes inside grid aren't at the same width though I set each of them to same width which is the total WizardPage width/4 (since I have four text boxes).
Any solution please?
Thanks!
To equally divide in 4 columns , you should use a grid, instead of a DockPanel. Although it is unnecessary to precide the Width. Just indicate that you have 4 columns :
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="200"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="Step 1" Background="#FF2BADDE" FontSize="16" TextAlignment="Center" />
<TextBox Grid.Column="1" Text="Step 2" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
<TextBox Grid.Column="2" Text="Step 3" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
<TextBox Grid.Column="3" Text="Step 4" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
</Grid>
<Grid Grid.Row="1">
<GroupBox Header="Group 1" FontSize="16" Height="80" Margin="0,0,0,90" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="270"/>
<ColumnDefinition Width="270"/>
</Grid.ColumnDefinitions>
<RadioButton x:Name="RadioButNew" Content="New" FontSize="13.333" BorderThickness="0,1,1,1" HorizontalAlignment="Left" Margin="30,30,0,0"/>
<RadioButton x:Name="RadioButUpdate" Content="Update" Grid.Column="1" FontSize="13.333" Focusable="False" HorizontalAlignment="Left" Margin="30,30,0,0"/>
</Grid>
</GroupBox>
</Grid>
</Grid>
you can also simplify you xaml by using only 1 grid. Grid.ColumnSpan is handy is such a case :
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="80"/>
<RowDefinition Height="200"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBox Grid.Row="0" Grid.Column="0" Text="Step 1" Background="#FF2BADDE" FontSize="16" TextAlignment="Center" />
<TextBox Grid.Row="0" Grid.Column="1" Text="Step 2" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
<TextBox Grid.Row="0" Grid.Column="2" Text="Step 3" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
<TextBox Grid.Row="0" Grid.Column="3" Text="Step 4" Background="#FF777A7C" FontSize="16" TextAlignment="Center" />
<GroupBox Header="Group 1" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" FontSize="16" Margin="0,0,0,90" />
<RadioButton Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" x:Name="RadioButNew" Content="New" FontSize="13.333" BorderThickness="0,1,1,1" HorizontalAlignment="Center" Margin="30,30,0,0"/>
<RadioButton Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" x:Name="RadioButUpdate" Content="Update" FontSize="13.333" Focusable="False" HorizontalAlignment="Center" Margin="30,30,0,0"/>
</Grid>

XAML Ellipse relative size

I want to make the size of an ellipse relative to its holding grids Column and Row size.
So, the size of the ellipses should change relative to the size of the page (device) of the given hardware..
Something like 'Inherit' from css.
Is this possible?
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="10*" />
<RowDefinition Height="10*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Ellipse Fill="DarkGray" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Stroke="Black" VerticalAlignment="Center" HorizontalAlignment="Center" Width="200" Height="200" />
<Ellipse Fill="DarkGray" Height="200" Width="200" Grid.Row="2" Grid.Column="1" Stroke="Black" VerticalAlignment="Center" HorizontalAlignment="Center" />
<Ellipse Fill="DarkGray" Height="200" Width="200" Grid.Row="2" Grid.Column="2" Stroke="Black" VerticalAlignment="Center" HorizontalAlignment="Center" />
<TextBlock Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="1" Grid.Row="2" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="2" Grid.Row="2" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
Use ViewBox for this purpose. For example, replace the 3rd Ellipse with the following code. It will grows/shrinks with the containing Grid.
<Viewbox Grid.Row="2" Grid.Column="2">
<Ellipse Fill="DarkGray" Height="200" Width="200" Stroke="Black" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Viewbox>

Print a usercontrol to the center of an A4 page

I have a user control which I need to print.
The form is just a basic filled out form. I have the controls all placed in a stackpanel which is named and the button for printing is outside the stackpanel, so the button is not printed with.
<UserControl x:Class="*****.PrintInitiateRequestFormView"
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:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
mc:Ignorable="d"
Style="{StaticResource TransitionAnimation}">
<ScrollViewer>
<Border Style="{StaticResource PanelWindowBackground}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel x:Name="PrntFrm"
Grid.Row="0">
<Border Grid.Row="1"
Grid.Column="1"
Margin="3,3,3,0"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Style="{StaticResource PanelWindowBackground}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="200" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Source="/Lamacs_8;component/Resources/Images/NMBM_Logo.jpg"
Stretch="Fill"
Grid.ColumnSpan="2"
Margin="0,0,74,0"
Width="265">
</Image>
<Label Grid.Row="1"
Grid.ColumnSpan="4"
HorizontalAlignment="Center"
Content="WORK REQUEST"
FontSize="20" />
<Label Grid.Row="2"
Grid.ColumnSpan="2"
Content="Call Centre"
FontSize="20">
</Label>
<Label Grid.Row="2"
Grid.Column="2"
FontSize="20"
Content="Reference Number:" />
<Label Grid.Row="2"
Grid.Column="3"
FontSize="16"
Content="{Binding RefNo}" />
<Label Grid.Row="3"
Grid.Column="2"
FontSize="16"
Content="Date & Time Logged:" />
<Label Grid.Column="3"
Grid.Row="3"
FontSize="16"
Content="{Binding CaptureDate}" />
<Label Grid.Row="4"
Grid.Column="0"
Content="Building:"
FontSize="16" />
<Label Grid.Row="4"
Grid.Column="1"
Content="{Binding LandObjectBuilding}"
FontSize="16" />
<Label Grid.Row="5"
Grid.Column="0"
Content="Address:"
FontSize="16" />
<Label Grid.Column="1"
Grid.Row="5"
FontSize="16"
Grid.ColumnSpan="2"
Content="{Binding LandObjectAddress}" />
<Label Grid.Row="6"
Grid.Column="0"
Content="Caller:"
FontSize="16" />
<Label Grid.Row="6"
Grid.Column="1"
Content="{Binding CallerName}"
FontSize="16" />
<Label Grid.Row="6"
Grid.Column="2"
Content="Telephone:"
FontSize="16" />
<Label Grid.Row="6"
Grid.Column="3"
Content="{Binding CallerTel}"
FontSize="16" />
<Label Grid.Row="7"
Grid.Column="0"
Content="Problem Description:"
FontSize="16" />
<TextBox Grid.Row="7"
Grid.Column="1"
Grid.ColumnSpan="3"
Height="50"
TextWrapping="Wrap"
Text="{Binding ProblemDesc}"
FontSize="16"
Background="Transparent"
BorderBrush="Transparent" />
<Label Grid.Row="8"
Grid.Column="2"
Content="Person Responsible:"
FontSize="16" />
<Label Grid.Row="8"
Grid.Column="3"
Content="{Binding Assistant}"
FontSize="16" />
<Label Grid.Row="8"
Grid.Column="0"
Content="Sector"
FontSize="16" />
<Label Grid.Row="8"
Grid.Column="1"
Content="{Binding Sector}"
FontSize="16" />
<Label Grid.Row="9"
Grid.Column="0"
Content="Component"
FontSize="16" />
<Label Grid.Row="9"
Grid.Column="1"
Content="{Binding Component}"
FontSize="16" />
<Label Grid.Row="9"
Grid.Column="2"
Content="Element"
FontSize="16" />
<Label Grid.Row="9"
Grid.Column="3"
Content="{Binding Element}"
FontSize="16" />
<Separator Grid.Row="11"
Grid.ColumnSpan="4" />
<Label Grid.Row="12"
Grid.Column="0"
Content="Official:"
FontSize="20" />
<Label Grid.Row="13"
Grid.Column="0"
Content="Scope Of Work:"
FontSize="16" />
<TextBox Grid.Row="13"
Grid.Column="1"
Grid.ColumnSpan="3"
FontSize="16"
TextWrapping="Wrap"
Text="{Binding ScopeOfWork}"
Background="Transparent"
BorderBrush="Transparent" />
<Label Grid.Row="14"
Grid.Column="0"
Content="Cost Estimate:"
FontSize="16" />
<Label Grid.Row="14"
Grid.Column="1"
FontSize="16"
Content="{Binding CostEstimate}" />
<Label Grid.Row="14"
Grid.Column="2"
Content="Name:"
FontSize="16" />
<Label Grid.Row="14"
Grid.Column="3"
FontSize="16"
Content="{Binding ReportName}" />
<Label FontSize="16"
Grid.Row="15"
Grid.Column="0"
Content="Date:" />
<Label Grid.Row="15"
Grid.Column="1"
Content="{Binding FormDate}"
FontSize="16" />
<Label Grid.Row="16"
Grid.Column="0"
Grid.ColumnSpan="4"
Content="(Obtain Quotes if required)"
FontSize="16"
HorizontalAlignment="Center" />
<Separator Grid.Row="17"
Grid.ColumnSpan="4" />
<Label FontSize="20"
Content="Admin"
Grid.Column="0"
Grid.Row="18" />
<Label FontSize="16"
Content="Funds Available:"
Grid.Column="0"
Grid.Row="19" />
<Label FontSize="16"
Content="Yes"
Grid.Column="1"
Grid.Row="19" />
<Label FontSize="16"
Content="No"
Grid.Column="1"
Grid.Row="19"
Margin="50,0,0,0" />
<Label Grid.Column="2"
Grid.Row="19"
Content="Vote/ISO Number:"
FontSize="16" />
<Label Grid.Row="19"
Grid.Column="3"
FontSize="16"
Content="{Binding VISONum}" />
<Separator Grid.ColumnSpan="4"
Grid.Row="20" />
<Label Grid.Row="21"
Grid.Column="0"
Content="Official:"
FontSize="20" />
<Label Grid.Row="22"
Grid.Column="0"
Content="Contractor:"
FontSize="16" />
<Label Grid.Row="22"
Grid.Column="1"
Grid.ColumnSpan="2"
FontSize="16"
Content="{Binding Contractor}" />
<Label Grid.Row="23"
Grid.Column="0"
Content="Order No:"
FontSize="16" />
<Label Grid.Row="23"
Grid.Column="1"
FontSize="16"
Content="{Binding OrderNo}" />
<Label Grid.Row="23"
Grid.Column="2"
Content="Date Issued:"
FontSize="16" />
<Label Grid.Row="23"
Grid.Column="3"
Content="{Binding DateIssued}"
FontSize="16" />
<Label Grid.Column="0"
Grid.Row="24"
FontSize="16"
Content="Cost of Works:" />
<Label Grid.Row="24"
Grid.Column="1"
FontSize="16"
Content="{Binding CostWorks}" />
<Label Content="Variance:"
FontSize="16"
Grid.Row="24"
Grid.Column="2" />
<Label Grid.Row="24"
Grid.Column="3"
FontSize="16"
Content="{Binding Variance}" />
<Label Grid.Column="0"
Grid.Row="25"
FontSize="16"
Content="Reason:" />
<Label Grid.Row="25"
Grid.Column="1"
Grid.ColumnSpan="3"
FontSize="16"
Content="{Binding Reason}" />
<Separator Grid.ColumnSpan="4"
Grid.Row="26" />
<Label Grid.Row="27"
Grid.Column="0"
Grid.ColumnSpan="3"
Content="I hereby declare that the cost of the works is fair and reasonable."
FontSize="16" />
<Label Grid.Row="28"
Grid.Column="0"
Content="Name:"
FontSize="16" />
<Label Grid.Row="28"
Grid.Column="1"
Grid.ColumnSpan="3"
VerticalContentAlignment="Bottom"
FontSize="16"
Height="40"
Content="......................................................................................................................" />
<Label Grid.Row="29"
Grid.Column="0"
Content="Date:"
FontSize="16" />
<Label Grid.Row="29"
Grid.Column="1"
Grid.ColumnSpan="3"
VerticalContentAlignment="Bottom"
FontSize="16"
Height="40"
Content="......................................................................................................................" />
<Label Grid.Row="30"
Grid.Column="0"
Content="Signature:"
FontSize="16" />
<Label Grid.Row="30"
Grid.Column="1"
Grid.ColumnSpan="3"
VerticalContentAlignment="Bottom"
FontSize="16"
Height="40"
Content="......................................................................................................................" />
</Grid>
</Border>
</StackPanel>
<StackPanel Grid.Row="1"
Orientation="Horizontal">
<Button Width="150"
Height="25"
Margin="4,0,0,5"
HorizontalAlignment="Left"
Template="{StaticResource PrintButtonTemplate}"
Click="Button_Click" />
<Button Width="150"
Height="25"
Margin="4,0,0,5"
HorizontalAlignment="Left"
Template="{StaticResource CloseButtonTemplate}"
x:Name="CloseButton"
Click="CloseButton_Click" />
</StackPanel>
</Grid>
</Border>
</ScrollViewer>
You can mind all the MVVM loading, that is done sepratly.
Anyway, using code behind, I basically add this to my button click:
PrintDialog prnt = new PrintDialog();
prnt.PrintVisual(PrntFrm, "Initiate Work Request");
This prints out my form (stackpanel), but it is not exactly centered on the page. It sits at the top left, and some of the text is cut off on the left side.
Using the PrintDialog methods, how does one set the size of the page to be printed, or just center the contents of the printable form? And also, how can I set the page orientation from PrintDialog?
Do I have to set the PrintableAreaHeight/Width, and how do I do so?
I got it.
PrintDialog prnt = new PrintDialog();
if (prnt.ShowDialog() == true)
{
Size pageSize = new Size(prnt.PrintableAreaWidth - 30, prnt.PrintableAreaHeight - 30);
PrntFrm.Measure(pageSize);
PrntFrm.Arrange(new Rect(15, 15, pageSize.Width, pageSize.Height));
prnt.PrintVisual(PrntFrm, "Work Request");
}
is for a potrait screen. sizes may change depending on the amount needed to print
and
PrintDialog prnt = new PrintDialog();
if (prnt.ShowDialog() == true)
{
prnt.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;
Size pageSize = new Size(prnt.PrintableAreaWidth + 30, prnt.PrintableAreaHeight + 300);
PrntFrm.Measure(pageSize);
PrntFrm.Arrange(new Rect(15, 15, pageSize.Height, pageSize.Width));
prnt.PrintVisual(PrntFrm, "Job Card");
}
is for landscape. again, size changes when needed

Stay on the same textbox control inside a listbox whilst using keyboard navigation

I'm very new to WPF so go easy
I have a bound list box which is bounce to a datasource.
I have created a data template for the items in the list box and some of the columns of data need to be editable. to make them editable I have created a bound textbox in a data template in a resource file.
My question is. Once I am in the textbox and have edited the data. How do I then use the keyboard to arrow down to the next line and have it automatically give focus to the same textbox on the next line down.
I have been searching for 2 days now but no solution seems to fit my problem
Template in resource file;
<DataTemplate x:Key="myTemplate" x:Name="dTemplate">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=b2b_StockCode}" Control.Template="{StaticResource lvTemplate}" Width="80"/>
<Label Content="{Binding Path=b2b_PartNo}" Control.Template="{StaticResource lvTemplate}" Width="70"/>
<Label Content="{Binding Path=b2b_desc}" Control.Template="{StaticResource lvTemplate}" Width="245"/>
<TextBox x:Name="liProfileStockQty" HorizontalContentAlignment="Right" Text="{Binding Path=b2b_ProfileStockQty}" Control.Template="{StaticResource lvTextBoxTemplate}" Width="50"/>
<Label Content="{Binding Path=b2b_StockQty}" Control.Template="{StaticResource lvLabelRightAlignTemplate}" Width="50"/>
<Label Content="{Binding Path=b2b_DBCost}" Control.Template="{StaticResource lvLabelRightAlignTemplate}" Width="50"/>
<Label Content="{Binding Path=b2b_InternetCost}" Control.Template="{StaticResource lvLabelRightAlignTemplate}" Width="50"/>
<Label Content="{Binding Path=b2b_PerCost}" Control.Template="{StaticResource lvLabelRightAlignTemplate}" Width="50"/>
<Label Content="{Binding Path=b2b_TotalCost}" Control.Template="{StaticResource lvLabelRightAlignTemplate}" Width="50"/>
<Separator Width="2"/>
<Label Content="{Binding Path=b2b_TradePrice}" Control.Template="{StaticResource lvLabelRightAlignTemplate}" Width="50"/>
<Label Content="{Binding Path=b2b_PerTrade}" Control.Template="{StaticResource lvLabelRightAlignTemplate}" Width="50"/>
<TextBox x:Name="liDiscountTrade" HorizontalContentAlignment="Right" Text="{Binding Path=b2b_DiscountTrade}" Control.Template="{StaticResource lvTextBoxTemplate}" Width="50"/>
</StackPanel>
</DataTemplate>
my Main Xaml looks like this...
<Window x:Class="B2BPricing.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:my="clr-namespace:B2BPricing"
Title="B2B Pricing" Height="768" Width="1024" WindowStartupLocation="CenterScreen"
WindowStyle="ThreeDBorderWindow" ResizeMode="CanMinimize" Icon="/B2BPricing;component/NewCEF.ico" >
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ListViewResources.xaml" />
</ResourceDictionary.MergedDictionaries>
<my:B2BPricingDataSet x:Key="b2bPricing" />
<CollectionViewSource x:Key="b2bPricingViewSource" Source="{Binding Path=B2bPricing, Source={StaticResource b2bPricing}}" />
<CollectionViewSource x:Key="b2bPricingsupplierViewSource" Source="{Binding Path=B2bPricing_supplier, Source={StaticResource b2bPricingViewSource}}" />
</ResourceDictionary>
</Window.Resources>
<Grid DataContext="{StaticResource b2bPricingViewSource}" Name="MainGrid" >
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="836,12,0,0" Name="resultLabel" VerticalAlignment="Top" />
<Label Content="Stock Code" Height="28" HorizontalAlignment="Left" Margin="13,34,0,0" Name="lblStockCode" VerticalAlignment="Top" />
<Label Content="Part No." Height="28" HorizontalAlignment="Right" Margin="0,34,864,0" Name="lblPartNo" VerticalAlignment="Top" />
<Label Content="Description" Height="28" HorizontalAlignment="Right" Margin="0,34,776,0" Name="lblDescription" VerticalAlignment="Top" />
<Grid HorizontalAlignment="Left" Margin="51,609,0,0" Name="grid2" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Stock Code" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="3" Name="b2b_StockCodeTextBox" Text="{Binding Path=b2b_StockCode, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" VerticalAlignment="Center" Width="120" />
</Grid>
<Grid HorizontalAlignment="Left" Margin="51,644,0,0" Name="grid1" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Description" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="3" Name="b2b_descTextBox" Text="{Binding Path=b2b_desc, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" VerticalAlignment="Center" Width="386" />
</Grid>
<Grid HorizontalAlignment="Left" Margin="297,609,0,0" Name="grdSupplier" VerticalAlignment="Top" Width="219">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Supplier" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Height="22" HorizontalAlignment="Left" Margin="3,4,0,6" Name="tbSupplier" VerticalAlignment="Center" Width="150" Text="159" />
</Grid>
<ListBox ItemsSource="{Binding}" ItemTemplate="{StaticResource myTemplate}" Height="542" HorizontalAlignment="Stretch"
Margin="0,60,0,0" Name="lbPricing" VerticalAlignment="Top" Width="983" IsManipulationEnabled="True"
SelectionMode="Extended" IsSynchronizedWithCurrentItem="True"
KeyboardNavigation.TabNavigation="Continue"
KeyboardNavigation.DirectionalNavigation="Once">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Label Content="{Binding Path=Name}" Padding="4" Background="{StaticResource myGroupingBrush}" Foreground="White">
</Label>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
<Button Content="_Load" Height="23" HorizontalAlignment="Left" Margin="52,694,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<ProgressBar HorizontalAlignment="Stretch" Margin="230,311,246,385" Name="progressBar1" VerticalAlignment="Stretch" Width="526" Visibility="Visible" IsIndeterminate="False" />
<Grid DataContext="{StaticResource b2bPricingsupplierViewSource}" HorizontalAlignment="Left" Margin="12,-3,0,0" Name="grid4" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Supplier: " Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" FlowDirection="LeftToRight" />
<Label Content="{Binding Path=sup_fullname}" Grid.Column="1" Grid.Row="0" Height="28" HorizontalAlignment="Left" Margin="3" Name="sup_fullnameLabel" VerticalAlignment="Center" />
</Grid>
<Button Content="_Show" Height="23" HorizontalAlignment="Left" Margin="156,694,0,0" Name="btnTextBoxContents" VerticalAlignment="Top" Width="75" Click="btnTextBoxContents_Click" />
</Grid>
and the c#:
private void btnTextBoxContents_Click(object sender, RoutedEventArgs e)
{
ListBoxItem item = (lbPricing.SelectedItem as ListBoxItem);
TextBox tb = (TextBox)lbPricing.ItemsPanel.FindName("liProfileStockQty", lbPricing);
//TextBox tb = dTemplate.FindName("liProfileStockQty") as TextBox;
resultLabel.Content = tb.Text;
}
This is not the only way I've tried. I also tried copying something like this.
foreach (LinePosition item in this.ListLinePositions.Items)
{
CheckBox cb = FindByName("checkedPosition",
(ListViewItem)this.ListLinePositions.ItemContainerGenerator.ContainerFromItem(item)) as CheckBox;
}
but replacing that examples checkbox with the textbox control i'm tring to find

Chess Board in Metro Style apps

I am just playing around with the Metro style apps. I wanted to create a simple chess board using the UniformGrid from Wpf but it seems like that it is not supported in Metro style apps. Are there any alternative ways in Metro Style apps to create a chess board?
Can't you just use an 8x8 Grid? Eight RowDefinitions and Eight ColumnDefinitions should get it.
Here's a very brute force method of doing this. As long as the grid's height and width make it square, the resultant items will be the appropriate proportions. You could also set the Height of each RowDefinition and the Width of each ColumnDefinition to the same arbitrary value and get it proportional.
For something like this, I might choose to add the controls in the codebehind, versus in the XAML, but that's a choice I leave up to you.
<Grid x:Name="LayoutRoot" Background="White" Width="400" Height="400" >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Background="Black" Grid.Row="0" Grid.Column="0"/>
<Border Background="Ivory" Grid.Row="0" Grid.Column="1"/>
<Border Background="Black" Grid.Row="0" Grid.Column="2"/>
<Border Background="Ivory" Grid.Row="0" Grid.Column="3"/>
<Border Background="Black" Grid.Row="0" Grid.Column="4"/>
<Border Background="Ivory" Grid.Row="0" Grid.Column="5"/>
<Border Background="Black" Grid.Row="0" Grid.Column="6"/>
<Border Background="Ivory" Grid.Row="0" Grid.Column="7"/>
<Border Background="Black" Grid.Row="2" Grid.Column="0"/>
<Border Background="Ivory" Grid.Row="2" Grid.Column="1"/>
<Border Background="Black" Grid.Row="2" Grid.Column="2"/>
<Border Background="Ivory" Grid.Row="2" Grid.Column="3"/>
<Border Background="Black" Grid.Row="2" Grid.Column="4"/>
<Border Background="Ivory" Grid.Row="2" Grid.Column="5"/>
<Border Background="Black" Grid.Row="2" Grid.Column="6"/>
<Border Background="Ivory" Grid.Row="2" Grid.Column="7"/>
<Border Background="Black" Grid.Row="4" Grid.Column="0"/>
<Border Background="Ivory" Grid.Row="4" Grid.Column="1"/>
<Border Background="Black" Grid.Row="4" Grid.Column="2"/>
<Border Background="Ivory" Grid.Row="4" Grid.Column="3"/>
<Border Background="Black" Grid.Row="4" Grid.Column="4"/>
<Border Background="Ivory" Grid.Row="4" Grid.Column="5"/>
<Border Background="Black" Grid.Row="4" Grid.Column="6"/>
<Border Background="Ivory" Grid.Row="4" Grid.Column="7"/>
<Border Background="Black" Grid.Row="6" Grid.Column="0"/>
<Border Background="Ivory" Grid.Row="6" Grid.Column="1"/>
<Border Background="Black" Grid.Row="6" Grid.Column="2"/>
<Border Background="Ivory" Grid.Row="6" Grid.Column="3"/>
<Border Background="Black" Grid.Row="6" Grid.Column="4"/>
<Border Background="Ivory" Grid.Row="6" Grid.Column="5"/>
<Border Background="Black" Grid.Row="6" Grid.Column="6"/>
<Border Background="Ivory" Grid.Row="6" Grid.Column="7"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="0"/>
<Border Background="Black" Grid.Row="1" Grid.Column="1"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="2"/>
<Border Background="Black" Grid.Row="1" Grid.Column="3"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="4"/>
<Border Background="Black" Grid.Row="1" Grid.Column="5"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="6"/>
<Border Background="Black" Grid.Row="1" Grid.Column="7"/>
<Border Background="Ivory" Grid.Row="3" Grid.Column="0"/>
<Border Background="Black" Grid.Row="3" Grid.Column="1"/>
<Border Background="Ivory" Grid.Row="3" Grid.Column="2"/>
<Border Background="Black" Grid.Row="3" Grid.Column="3"/>
<Border Background="Ivory" Grid.Row="3" Grid.Column="4"/>
<Border Background="Black" Grid.Row="3" Grid.Column="5"/>
<Border Background="Ivory" Grid.Row="3" Grid.Column="6"/>
<Border Background="Black" Grid.Row="3" Grid.Column="7"/>
<Border Background="Ivory" Grid.Row="5" Grid.Column="0"/>
<Border Background="Black" Grid.Row="5" Grid.Column="1"/>
<Border Background="Ivory" Grid.Row="5" Grid.Column="2"/>
<Border Background="Black" Grid.Row="5" Grid.Column="3"/>
<Border Background="Ivory" Grid.Row="5" Grid.Column="4"/>
<Border Background="Black" Grid.Row="5" Grid.Column="5"/>
<Border Background="Ivory" Grid.Row="5" Grid.Column="6"/>
<Border Background="Black" Grid.Row="5" Grid.Column="7"/>
<Border Background="Ivory" Grid.Row="7" Grid.Column="0"/>
<Border Background="Black" Grid.Row="7" Grid.Column="1"/>
<Border Background="Ivory" Grid.Row="7" Grid.Column="2"/>
<Border Background="Black" Grid.Row="7" Grid.Column="3"/>
<Border Background="Ivory" Grid.Row="7" Grid.Column="4"/>
<Border Background="Black" Grid.Row="7" Grid.Column="5"/>
<Border Background="Ivory" Grid.Row="7" Grid.Column="6"/>
<Border Background="Black" Grid.Row="7" Grid.Column="7"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="0"/>
<Border Background="Black" Grid.Row="1" Grid.Column="1"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="2"/>
<Border Background="Black" Grid.Row="1" Grid.Column="3"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="4"/>
<Border Background="Black" Grid.Row="1" Grid.Column="5"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="6"/>
<Border Background="Black" Grid.Row="1" Grid.Column="7"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="0"/>
<Border Background="Black" Grid.Row="1" Grid.Column="1"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="2"/>
<Border Background="Black" Grid.Row="1" Grid.Column="3"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="4"/>
<Border Background="Black" Grid.Row="1" Grid.Column="5"/>
<Border Background="Ivory" Grid.Row="1" Grid.Column="6"/>
<Border Background="Black" Grid.Row="1" Grid.Column="7"/>
</Grid>
If you plan on using databinding you can use a WrapGrid with the MaximumRowsOrColumns property set to 8. Then bind to a collection of 64 items that contain the state of the board.
WrapGrid API Reference
UniformGrid isn't necessary with ViewBox:
<Window
x:Class="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:ChessGUI"
mc:Ignorable="d"
Title="Chess GUI"
Height="640"
Width="640" Background="PaleGreen"
>
<Viewbox Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="16" >
<Grid Background="White" Width="256" Height="256">
<Grid.RowDefinitions>
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
<RowDefinition Height="*" />
<RowDefinition Height="0" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="0" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Row="1" Grid.Column="1" Fill="LightGray" />
<Rectangle Grid.Row="1" Grid.Column="3" Fill="DarkGray" />
<Rectangle Grid.Row="1" Grid.Column="5" Fill="LightGray" />
<Rectangle Grid.Row="1" Grid.Column="7" Fill="DarkGray" />
<Rectangle Grid.Row="1" Grid.Column="9" Fill="LightGray" />
<Rectangle Grid.Row="1" Grid.Column="11" Fill="DarkGray" />
<Rectangle Grid.Row="1" Grid.Column="13" Fill="LightGray" />
<Rectangle Grid.Row="1" Grid.Column="15" Fill="DarkGray" />
<Rectangle Grid.Row="3" Grid.Column="1" Fill="DarkGray" />
<Rectangle Grid.Row="3" Grid.Column="3" Fill="LightGray" />
<Rectangle Grid.Row="3" Grid.Column="5" Fill="DarkGray" />
<Rectangle Grid.Row="3" Grid.Column="7" Fill="LightGray" />
<Rectangle Grid.Row="3" Grid.Column="9" Fill="DarkGray" />
<Rectangle Grid.Row="3" Grid.Column="11" Fill="LightGray" />
<Rectangle Grid.Row="3" Grid.Column="13" Fill="DarkGray" />
<Rectangle Grid.Row="3" Grid.Column="15" Fill="LightGray" />
<Rectangle Grid.Row="5" Grid.Column="1" Fill="LightGray" />
<Rectangle Grid.Row="5" Grid.Column="3" Fill="DarkGray" />
<Rectangle Grid.Row="5" Grid.Column="5" Fill="LightGray" />
<Rectangle Grid.Row="5" Grid.Column="7" Fill="DarkGray" />
<Rectangle Grid.Row="5" Grid.Column="9" Fill="LightGray" />
<Rectangle Grid.Row="5" Grid.Column="11" Fill="DarkGray" />
<Rectangle Grid.Row="5" Grid.Column="13" Fill="LightGray" />
<Rectangle Grid.Row="5" Grid.Column="15" Fill="DarkGray" />
<Rectangle Grid.Row="7" Grid.Column="1" Fill="DarkGray" />
<Rectangle Grid.Row="7" Grid.Column="3" Fill="LightGray" />
<Rectangle Grid.Row="7" Grid.Column="5" Fill="DarkGray" />
<Rectangle Grid.Row="7" Grid.Column="7" Fill="LightGray" />
<Rectangle Grid.Row="7" Grid.Column="9" Fill="DarkGray" />
<Rectangle Grid.Row="7" Grid.Column="11" Fill="LightGray" />
<Rectangle Grid.Row="7" Grid.Column="13" Fill="DarkGray" />
<Rectangle Grid.Row="7" Grid.Column="15" Fill="LightGray" />
<Rectangle Grid.Row="9" Grid.Column="1" Fill="LightGray" />
<Rectangle Grid.Row="9" Grid.Column="3" Fill="DarkGray" />
<Rectangle Grid.Row="9" Grid.Column="5" Fill="LightGray" />
<Rectangle Grid.Row="9" Grid.Column="7" Fill="DarkGray" />
<Rectangle Grid.Row="9" Grid.Column="9" Fill="LightGray" />
<Rectangle Grid.Row="9" Grid.Column="11" Fill="DarkGray" />
<Rectangle Grid.Row="9" Grid.Column="13" Fill="LightGray" />
<Rectangle Grid.Row="9" Grid.Column="15" Fill="DarkGray" />
<Rectangle Grid.Row="11" Grid.Column="1" Fill="DarkGray" />
<Rectangle Grid.Row="11" Grid.Column="3" Fill="LightGray" />
<Rectangle Grid.Row="11" Grid.Column="5" Fill="DarkGray" />
<Rectangle Grid.Row="11" Grid.Column="7" Fill="LightGray" />
<Rectangle Grid.Row="11" Grid.Column="9" Fill="DarkGray" />
<Rectangle Grid.Row="11" Grid.Column="11" Fill="LightGray" />
<Rectangle Grid.Row="11" Grid.Column="13" Fill="DarkGray" />
<Rectangle Grid.Row="11" Grid.Column="15" Fill="LightGray" />
<Rectangle Grid.Row="13" Grid.Column="1" Fill="LightGray" />
<Rectangle Grid.Row="13" Grid.Column="3" Fill="DarkGray" />
<Rectangle Grid.Row="13" Grid.Column="5" Fill="LightGray" />
<Rectangle Grid.Row="13" Grid.Column="7" Fill="DarkGray" />
<Rectangle Grid.Row="13" Grid.Column="9" Fill="LightGray" />
<Rectangle Grid.Row="13" Grid.Column="11" Fill="DarkGray" />
<Rectangle Grid.Row="13" Grid.Column="13" Fill="LightGray" />
<Rectangle Grid.Row="13" Grid.Column="15" Fill="DarkGray" />
<Rectangle Grid.Row="15" Grid.Column="1" Fill="DarkGray" />
<Rectangle Grid.Row="15" Grid.Column="3" Fill="LightGray" />
<Rectangle Grid.Row="15" Grid.Column="5" Fill="DarkGray" />
<Rectangle Grid.Row="15" Grid.Column="7" Fill="LightGray" />
<Rectangle Grid.Row="15" Grid.Column="9" Fill="DarkGray" />
<Rectangle Grid.Row="15" Grid.Column="11" Fill="LightGray" />
<Rectangle Grid.Row="15" Grid.Column="13" Fill="DarkGray" />
<Rectangle Grid.Row="15" Grid.Column="15" Fill="LightGray" />
</Grid>
</Viewbox>
</Window>

Categories