WPF application controls don't resize after minimize - c#

i'm developing a WPF Application; my problem is when i maximise windows and after i minimize / resize it; the control, on maximise going well but when i minimize/resize window, control(textblock, combobox) don't and maintain maximized dimension.
how can i make my control resize on minimise?
Here a semple of my XAML code:
<UserControl x:Class="MyNamespace.UC.Suppliers_Insert"
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:local="clr-namespace:MyNamespace.UC"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<DockPanel Name="MainDock" LastChildFill="True" DataContext="{Binding Suppliers_Insert, Source={StaticResource Locator}}"
VerticalAlignment="Stretch"
Height="Auto">
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Name="wRow0" Height="*"/>
<RowDefinition Name="wRow1" Height="*"/>
<RowDefinition Name="wRow2" Height="*"/>
<RowDefinition Name="wRow3" Height="*"/>
<RowDefinition Name="wRow4" Height="*"/>
</Grid.RowDefinitions>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="0" WatermarkContent="Supplier Name" Text="{Binding SupplierModel.Supplier_Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Supplier_Name_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="1" WatermarkContent="Vat Number" Text="{Binding SupplierModel.VAT_Number, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding VAT_Number_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="2" WatermarkContent="Tax Code" Text="{Binding SupplierModel.Tax_Code, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Tax_Code_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="3" WatermarkContent="External Supplier ID" Text="{Binding SupplierModel.External_Supplier_ID, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding External_Supplier_ID_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="3" WatermarkContent="Note" AcceptsReturn="True" Text="{Binding SupplierModel.Note, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Note_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" WatermarkContent="Website" Text="{Binding SupplierModel.Website, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource RadWatermarkTextBoxStyle_UserNamme}" Margin="5,5,5,0" Visibility="{Binding Website_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
Validation.ErrorTemplate="{StaticResource MyTemplateError}"/>
<telerik:RadButton x:Name="rdb_Insert" Grid.Row="3" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Content="{DynamicResource rsBtn_Insert}" Width="75"
Visibility="{Binding InsertButtonVisibility}" Command="{Binding SaveNavigationCommand}" />
<telerik:RadButton x:Name="rdb_Cancel" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Content="{DynamicResource rsBtn_Cancel}" Width="75"
Command="{Binding CancelNavigationCommand}" Visibility="{Binding CancelButtonVisibility}" />
<telerik:RadButton x:Name="rdb_Close" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center"
Content="{DynamicResource rsBtn_Close}" Width="75" Command="{Binding CancelButtonVisibility}" Visibility="{Binding CloseButtonVisibility}"/>
</Grid>
</Grid>
</DockPanel>
Thanks.
EDIT:
I forgot to indicate that UC is into a StackPanel in my MainView. I've change the SP to a Grid and now content will resize correctly when windows minimise.

I did debugging of your usercontrol and for that i have to remove the command and styles you have used in the xaml. I can able to see the controls minimize or maximize on window resize. I am sure the problem is with your styles you have applied to the controls.
The code i have used is:
<DockPanel Name="MainDock" LastChildFill="True"
VerticalAlignment="Stretch"
Height="Auto">
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Name="wRow0" Height="*"/>
<RowDefinition Name="wRow1" Height="*"/>
<RowDefinition Name="wRow2" Height="*"/>
<RowDefinition Name="wRow3" Height="*"/>
<RowDefinition Name="wRow4" Height="*"/>
</Grid.RowDefinitions>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="0" WatermarkContent="Supplier Name" Text="{Binding SupplierModel.Supplier_Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0" Visibility="{Binding Supplier_Name_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="1" WatermarkContent="Vat Number" Text="{Binding SupplierModel.VAT_Number, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0" Visibility="{Binding VAT_Number_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="2" WatermarkContent="Tax Code" Text="{Binding SupplierModel.Tax_Code, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0" Visibility="{Binding Tax_Code_Visibility}" IsEnabled="{Binding Supplier_Fields_Enable}"
/>
<telerik:RadWatermarkTextBox Grid.Column="0" Grid.Row="3" WatermarkContent="External Supplier ID" Text="{Binding SupplierModel.External_Supplier_ID, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0"
/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="3" WatermarkContent="Note" AcceptsReturn="True" Text="{Binding SupplierModel.Note, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0"
/>
<telerik:RadWatermarkTextBox Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" WatermarkContent="Website" Text="{Binding SupplierModel.Website, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Margin="5,5,5,0"
/>
<telerik:RadButton x:Name="rdb_Insert" Grid.Row="3" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Width="75"
/>
<telerik:RadButton x:Name="rdb_Cancel" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center" Width="75"
/>
<telerik:RadButton x:Name="rdb_Close" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Right" Margin="10,0,10,0" VerticalAlignment="Center"
Width="75" />
</Grid>
</Grid>
</DockPanel>

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>

How to Stop WPF TextBox from growing

WPF TextBox Control grows when a long text has been typed in.
This question has been already raised in Stackoverflow
and I refereed few answers also, but still I didn't find the proper answer which is working.
Here same problem has been mentioned but no working solution for this kind of issue.
I have spend enough time to solve this, please help me to solve this issue.
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<DockPanel LastChildFill="False" Grid.IsSharedSizeScope="True">
<GroupBox DockPanel.Dock="Top" DataContext="{Binding Data, ValidatesOnNotifyDataErrors=False}">
<GroupBox.HeaderTemplate>
<DataTemplate>
<TextBlock shell:Localization.VbeiTag="vbeiGeneralInformation" Text="General Information"/>
</DataTemplate>
</GroupBox.HeaderTemplate>
<Grid DockPanel.Dock="Top" Margin="0,0,0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="GroupA" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" SharedSizeGroup="GroupB" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!--Code Prefix Label -->
<Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Content="Code" ></Label>
<Label Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" Content="Name" ></Label>
<Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="Title" ></Label>
<Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Content="Long Reference" ></Label>
<Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Content="Client Reference"></Label>
<Label Grid.Row="3" Grid.Column="2" HorizontalAlignment="Left" Content="Lead Sub-Business Unit" ></Label>
<!--Code Prefix Editor-->
<common:StudyCodeEditor Grid.Row="0" Grid.Column="1" DataContext="{Binding ValidatesOnNotifyDataErrors=False}"
SuggestedStudyCodePrefixRange="{ViewModelBinding SuggestedStudyCodePrefixRange}"/>
<!--Study Name-->
<TextBox Grid.Row="0" Grid.Column="3" Margin="3" VerticalAlignment="Top"
Text="{Binding StudyName, UpdateSourceTrigger=PropertyChanged}" />
<!--Study Title -->
<TextBox Grid.Row="1" Grid.Column="1" Margin="3" Grid.ColumnSpan="3" VerticalAlignment="Top"
Text="{Binding StudyOfficialTitle, UpdateSourceTrigger=PropertyChanged}" />
<!--Client Long Reference -->
<TextBox Grid.Row="2" Grid.Column="1" Margin="3" Grid.ColumnSpan="3" VerticalAlignment="Top"
Text="{Binding StudyClientLongReference, UpdateSourceTrigger=PropertyChanged}" />
<!--Client Study Reference-->
<TextBox Grid.Row="3" Grid.Column="1" Margin="3" VerticalAlignment="Top"
Text="{Binding ClientStudyReference, UpdateSourceTrigger=PropertyChanged}" />
<!-- Description -->
<TextBox Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="3"
Text="{Binding Description}" AcceptsReturn="True" DockPanel.Dock="Top"
TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Margin="3" Height="62"/>
</Grid>
</GroupBox>
</DockPanel>
</ScrollViewer>
MaxWidth should do the trick. If not, what went wrong in your case?

Why don't my columns align like they should?

With the following XAML I get this layout:
<GroupBox Header="Adres" Grid.Row="1" Grid.RowSpan="5">
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label HorizontalAlignment="Left" Content="Straat:"/>
<TextBox Margin="130,0,0,0" Text="{Binding Address.Street}" Grid.Column="1" Grid.ColumnSpan="3" />
<Label HorizontalAlignment="Left" Grid.Row="1" Content="Nr:"/>
<TextBox Margin="130,0,0,0" Text="{Binding Address.Number}" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" />
<Label HorizontalAlignment="Left" Grid.Row="1" Content="Ext:" Grid.Column="3"/>
<TextBox Margin="130,0,0,0" Text="{Binding Address.NumberExtension}" Grid.Row="1" Grid.Column="3" />
<Label HorizontalAlignment="Left" Content="Gemeente:" Grid.Row="2"/>
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext.Towns}" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch">
</ComboBox>
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext.Towns}" Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="2">
</ComboBox>
<Label Width="125" HorizontalAlignment="Left" Content="Land:" Grid.Row="3"/>
<TextBox Margin="130,0,0,0" Text="{Binding Address.Country}" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="3" />
</Grid>
</GroupBox>
Why don't my textboxes align with the columns I made? And why do the ComboBoxes DO align with the columns?
It seems the margins in your textboxes have been mistakenly set, causing their positioning to be misaligned with the grid's columns.

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

Silverlight TabItem content not scrolling

I have this XAML where I have tried to get TabItem content to scroll (without success).
<ex:TabControl>
<ex:TabItem Header="General">
<ContentPresenter Content="{Binding }" ContentTemplate="{StaticResource tabMenuItem}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</ex:TabItem>
<ex:TabItem Header="Prices (Item)">
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto">
<ContentPresenter Content="{Binding NonModifierPricesView}" ContentTemplate="{StaticResource tabMenuItemPrices}" />
</ScrollViewer>
</ex:TabItem>
</ex:TabControl>
When my TabControl gets resized so that the TabItem is too small to display all the content, no scrollbars are displayed. Have I done something wrong somewhere?
Edit : Requested XAML for tabMenuItemPrices
<DataTemplate x:Key="tabMenuItemPrices">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Prices (in order of priority)" />
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListBox HorizontalAlignment="Stretch" Margin="{StaticResource DefaultMargin}" x:Name="lstMenuItemPrices" SelectionMode="Single"
ItemsSource="{Binding }" ItemTemplate="{StaticResource MenuItemPriceDataTemplate}" Height="140" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding DataContext.UpdateSelectedTaxGroupsCommand, ElementName=Editor}" CommandParameter="{Binding SelectedItem, ElementName=lstMenuItemPrices}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
<StackPanel VerticalAlignment="Center" Grid.Column="1" >
<Button Content="Move Up" HorizontalAlignment="Center" Margin="2" IsEnabled="{Binding SelectedIndex, Converter={StaticResource MinimumIntegerToBooleanConverter}, ConverterParameter=0, ElementName=lstMenuItemPrices, Mode=OneWay}" />
<Button Content="Move Down" HorizontalAlignment="Center" Margin="2" IsEnabled="{Binding SelectedIndex, Converter={StaticResource MinimumIntegerToBooleanConverter}, ConverterParameter=0, ElementName=lstMenuItemPrices, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.ColumnSpan="2">
<Button HorizontalAlignment="Left" Margin="2" Content="New Price" Command="{Binding DataContext.AddPriceCommand, ElementName=Editor}" />
<Button Content="Remove Price" HorizontalAlignment="Left" Margin="2" Command="{Binding DataContext.RemovePriceCommand, ElementName=Editor}" CommandParameter="{Binding SelectedItem, ElementName=lstMenuItemPrices}"
IsEnabled="{Binding SelectedIndex, Converter={StaticResource MinimumIntegerToBooleanConverter}, ConverterParameter=0, ElementName=lstMenuItemPrices, Mode=OneWay}"/>
</StackPanel>
</Grid>
<TextBlock Text="Selected Price" Grid.Row="2" />
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<CheckBox Content="Amount Includes Tax" d:LayoutOverrides="Width, Height" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center"
IsChecked="{Binding SelectedItem.DTO.AmountIncludesTax, Mode=TwoWay, ElementName=lstMenuItemPrices}" Grid.ColumnSpan="3"/>
<TextBlock HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Text="Amount" Grid.Row="1"/>
<TextBlock Text="Cost" d:LayoutOverrides="Width, Height, GridBox" HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Row="2"/>
<TextBlock HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Text="Points" Grid.Row="3"/>
<TextBlock HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Text="Interface ID" Grid.Row="4"/>
<TextBox VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" Margin="{StaticResource DefaultMargin}"
Text="{Binding SelectedItem.DTO.Amount, Mode=TwoWay, ElementName=lstMenuItemPrices, Converter={StaticResource DecimalToMoneyStringConverter}}" />
<CheckBox Content="Open" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Row="1" Grid.Column="2"
IsChecked="{Binding SelectedItem.DTO.IsOpenAmount, Mode=TwoWay, ElementName=lstMenuItemPrices}"/>
<TextBox Text="{Binding SelectedItem.DTO.Cost, Converter={StaticResource DecimalToMoneyStringConverter}, Mode=TwoWay, ElementName=lstMenuItemPrices}" TextWrapping="Wrap"
Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" d:LayoutOverrides="GridBox" Grid.Column="1" Grid.Row="2"/>
<CheckBox Content="Inherit" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Column="2" Grid.Row="2"
IsChecked="{Binding SelectedItem.DTO.CostOverride, Converter={StaticResource CostToBooleanConverter}, Mode=TwoWay, ElementName=lstMenuItemPrices}" />
<TextBox Text="{Binding SelectedItem.DTO.PointsEarned, Converter={StaticResource IntegerToStringConverter}, Mode=TwoWay, ElementName=lstMenuItemPrices}" TextWrapping="Wrap"
Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Column="1" Grid.Row="3"
IsEnabled="{Binding SelectedItem.DTO.PointsEarnedInherited, Converter={StaticResource ReverseBooleanConverter}, ElementName=lstMenuItemPrices}"/>
<CheckBox Content="Inherit" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Column="2" Grid.Row="3"
IsChecked="{Binding SelectedItem.DTO.InheritPointsEarned, Mode=TwoWay, ElementName=lstMenuItemPrices}" />
<TextBox Margin="{StaticResource DefaultMargin}" Grid.Column="1" Grid.Row="4"
Text="{Binding SelectedItem.DTO.InterfaceID, Mode=TwoWay, ElementName=lstMenuItemPrices}" />
<CheckBox Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Content="Inherit tax from class" HorizontalAlignment="Left"
IsChecked="{Binding SelectedItem.DTO.InheritTaxes, Mode=TwoWay, ElementName=lstMenuItemPrices}" Grid.Row="5" Grid.ColumnSpan="3" />
<ListBox Margin="{StaticResource DefaultMargin}" Grid.Row="6" Grid.ColumnSpan="3" SelectionMode="Multiple" ItemsSource="{Binding DataContext.Repository.TaxGroups, ElementName=Editor}"
IsEnabled="{Binding SelectedItem.DTO.InheritTaxes, Converter={StaticResource BooleanToEnabledConverter}, ElementName=lstMenuItemPrices, ConverterParameter=false}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" >
<Setter Property="Margin" Value="2, 2, 2, 0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="Transparent">
<CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
Content="{Binding DTO.Name}" Padding="5,0,10,0" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<cmd:EventToCommand Command="{Binding SelectedItem.AddTaxGroupCommand, ElementName=lstMenuItemPrices}" CommandParameter="{Binding DTO.ID}" />
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<cmd:EventToCommand Command="{Binding SelectedItem.RemoveTaxGroupCommand, ElementName=lstMenuItemPrices}" CommandParameter="{Binding DTO.ID}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</Grid>
</Grid>
</DataTemplate>
The ScrollViewer's child needs to manage it's own height and width. Your outer most grid in your ContentTemplate does not specify a HorizontalAlignment or VerticalAlignment so it's defaulting to a value of stretch... you can try setting the alignments to left and top as follows:
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
The bottom line is, the outer most container inside your control template must set it's height and width to it's contents, not the parent container.

Categories