I have the following control, the first row is a header row. There will always be at least one additional row. (minimum of 2 total rows).
I've thought about making the content row into a UserControl but unsure about how to set the content of the UserControl into the two columns. (Stack in Column 0 and TriggerForWord in Column 1)
What is the best way to implement adding rows dynamically and setting the content? UserControl loaded into each row? Something else?
<Grid Grid.Row="3" Margin="10,10,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Static localization:Resources.WordToTriggerAction}}" Margin="2 8 2 8" FontWeight="SemiBold" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Source={x:Static localization:Resources.Trigger}}" Margin="12 8 2 8" FontWeight="SemiBold" />
<!-- dynamic part -->
<StackPanel x:Name="Stack" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Margin="0,0,10,20" VerticalAlignment="Top">
<telerik:RadAutoCompleteBox x:Name="WordForAction" Width="300" WatermarkContent="{Binding Source={x:Static localization:Resources.EnterWordForAction}}" Margin="0" ItemsSource="{Binding Path=Words}"
DisplayMemberPath="word" SelectionMode="Single" AutoCompleteMode="Append" SearchTextChanged="WordForAction_SearchTextChanged" />
<Button IsEnabled="{Binding Path=SearchText.Length, ElementName=WordForAction}" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphPlus}" ToolTip="{Binding Source={x:Static localization:Resources.AddWord}}" VerticalAlignment="Bottom" />
<Button IsEnabled="{Binding Path=SearchText.Length, ElementName=WordForAction}" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphMinus}" ToolTip="{Binding Source={x:Static localization:Resources.RemoveWord}}" VerticalAlignment="Bottom" />
</StackPanel>
<telerik:RadComboBox x:Name="TriggerForWord" Grid.Row="1" Grid.Column="1" Width="150" EmptyText="{Binding Source={x:Static localization:Resources.Trigger}}" IsEditable="False" IsEnabled="False" SelectedValuePath="uuid" SelectionChanged="TriggerForWord_SelectionChanged"
Height="{Binding ElementName=WordForAction, Path=ActualHeight}" Margin="10 0 0 0" ItemsSource="{Binding Path=Triggers}" DisplayMemberPath="description" VerticalAlignment="Top" />
</Grid>
For other folks who come this way ...
<Grid Grid.Row="3" Margin="0,10,0,0" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="310"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Static localization:Resources.WordToTriggerAction}}" Margin="2 8 2 8" FontWeight="SemiBold" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Source={x:Static localization:Resources.Trigger}}" Margin="2 8 2 8" FontWeight="SemiBold" />
<ItemsControl Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding Path=WordsForAction}" x:Name="WordsForActionItems" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0, 0, 0, 5">
<StackPanel Orientation="Horizontal" Margin="0" VerticalAlignment="Top" Width="310">
<telerik:RadAutoCompleteBox x:Name="WordForAction" Width="250" WatermarkContent="{Binding Source={x:Static localization:Resources.EnterWordForAction}}" Margin="0"
ItemsSource="{Binding Path=Words, ElementName=_this}" DisplayMemberPath="Word" SearchText="{Binding Word}"
SelectionMode="Single" AutoCompleteMode="Append" SearchTextChanged="WordForAction_SearchTextChanged" />
<Button Name="AddWord" IsEnabled="True" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphPlus}" Click="AddWord_Click" ToolTip="{Binding Source={x:Static localization:Resources.AddWord}}" VerticalAlignment="Bottom" />
<Button Name="RemoveWord" IsEnabled="{Binding Items.Count, ElementName=WordsForActionItems, Converter={StaticResource CountToBoolConverter}}" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphMinus}" Click="RemoveWord_Click" ToolTip="{Binding Source={x:Static localization:Resources.RemoveWord}}" VerticalAlignment="Bottom" />
</StackPanel>
<telerik:RadComboBox Grid.Column="1" x:Name="TriggerForWord" Width="150" EmptyText="Trigger" IsEditable="False" IsEnabled="True" SelectionChanged="TriggerForWord_SelectionChanged"
Margin="0" ItemsSource="{Binding Path=Triggers, ElementName=_this}" SelectedValuePath="uuid" DisplayMemberPath="description" SelectedValue="{Binding Trigger_uuid}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Related
I have an interface with some tabs in it on the right side of the screen. I need each tab`s width to be resized by width of the context in it.
All the other tabs do it apart from this one...
Any suggestions, please?
Description
The scales tab in the stackup editor doesn’t resize when selected.
Select the scales tab on the right side of the stackup editor
Right hand tab doesn’t resize
Expected Behaviour
Tab resizes to fit content, as with all other tabs in the stackup
editor
enter image description here
<infrastructure:Plugin x:Class="Xact.GeminiX.Plugin.PanelEditors.Views.DisplayScalesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infrastructure="clr-namespace:Xact.GeminiX.Client.Common.Infrastructure;assembly=Xact.GeminiX.Client.Common"
xmlns:converters="clr-namespace:Xact.GeminiX.Client.Wpf.Common.Converters;assembly=Xact.GeminiX.Client.Wpf.Common"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
LayoutUpdated="ViewLayoutUpdated"
Loaded="Plugin_Loaded">
<infrastructure:Plugin.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></BooleanToVisibilityConverter>
<converters:BooleanToVisibilityHiddenOnFalseConverter x:Key="BooleanToVisibilityHiddenOnFalseConverter"></converters:BooleanToVisibilityHiddenOnFalseConverter>
<infrastructure:DataContextProxy x:Key="DataContextProxy"/>
</infrastructure:Plugin.Resources>
<i:Interaction.Behaviors>
<infrastructure:DataContextProxyBehavior DataContextProxy="{StaticResource DataContextProxy}"/>
</i:Interaction.Behaviors>
<Grid Grid.IsSharedSizeScope="True" PreviewMouseWheel="UIElement_OnPreviewMouseWheel">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.Resources>
<ContextMenu x:Key="ImportContextMenu"
ItemsSource="{Binding DataContext.ScalingImportExportMetaData.ScalingImportFormats, Source={StaticResource DataContextProxy}}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header"
Value="{Binding FormatTitle}"/>
<Setter Property="Command"
Value="{Binding DataContext.FormatSelectionCommand, Source={StaticResource DataContextProxy}}"/>
<Setter Property="CommandParameter"
Value="{Binding}"/>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
<ContextMenu x:Key="ImportFromStackupContextMenu">
<MenuItem Header="{Binding StoredLocalisation}" Click="ButtonImportFromStackupStored_OnClick"/>
<MenuItem Header="{Binding RemakesLocalisation}" Click="ButtonImportFromStackupRemakes_OnClick"/>
</ContextMenu>
<ContextMenu x:Key="ContextMenu" ItemsSource="{Binding DataContext.ScalingImportExportMetaData.ScalingExportFormats, Source={StaticResource DataContextProxy}}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header"
Value="{Binding FormatTitle}"/>
<EventSetter Event="Click"
Handler="MenuItem_OnClick"/>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
<DataTemplate x:Key="ExportButtonTemplate">
<telerik:RadButton Content="{Binding TypeTitle}" Click="ButtonBase_OnClick" IsEnabled="{Binding Enabled}" ContextMenu="{StaticResource ContextMenu}" Margin="2"/>
</DataTemplate>
</Grid.Resources>
<ScrollViewer VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Auto"
HorizontalAlignment="Left"
HorizontalContentAlignment="Left"
Grid.Column="0">
<Grid>
<Grid.Resources>
<converters:BooleanInvertConverter x:Key="BooleanInvertConverter"></converters:BooleanInvertConverter>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" SharedSizeGroup="B"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" SharedSizeGroup="C"/>
<RowDefinition Height="Auto" SharedSizeGroup="D"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Loaded="TopGrid_OnLoaded" HorizontalAlignment="Left" x:Name="Grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding LayerLocalisation}" Margin="5" />
<TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding FirstScaleFactorLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" Text="{Binding SecondScaleFactorLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding ArtworkLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="2" Text="{Binding PredictedLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="3" Text="{Binding ArtworkLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="4" Text="{Binding PredictedLocalisation}" HorizontalAlignment="Center" Margin="5" />
<Border Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="5"
BorderThickness="0, 1, 0, 0"
Margin="0, 5, 0, 5"
BorderBrush="LightGray" />
<TextBlock Grid.Row="3"
Grid.Column="0"
Text="{Binding AllLocalisation}"
VerticalAlignment="Center"
Margin="5" />
<TextBox x:Name="EnabledTemplate"
Grid.Row="3"
Grid.Column="1"
Margin="5"
Text="{Binding ShortValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
KeyDown="SetShortValues_OnKeyDown"
TextChanged="ShortValueTextbox_TextChanged"
Width="80"
IsEnabled="{Binding ScalesExist}"
MaxLength="10" />
<telerik:RadButton Grid.Row="3"
Grid.Column="2"
Content="{Binding SetFirstLocalisation}"
Click="SetShortButton_OnClick"
IsEnabled="{Binding ScalesExist}"
Margin="2"/>
<TextBox Grid.Row="3"
Grid.Column="3"
Margin="5"
Text="{Binding LongValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
KeyDown="SetLongValues_OnKeyDown"
TextChanged="ShortValueTextbox_TextChanged"
Width="80"
IsEnabled="{Binding ScalesExist}"
MaxLength="10" />
<telerik:RadButton Grid.Row="3"
Grid.Column="4"
Content="{Binding SetSecondLocalisation}"
Click="SetLongButton_OnClick"
IsEnabled="{Binding ScalesExist}"
Margin="2"/>
<CheckBox Grid.Row="4"
Grid.Column="0"
IsEnabled="{Binding ScalesExist}"
IsChecked="{Binding AllCheckboxIsChecked}"
Margin="5"
Click="SetAllCheckBoxToggled" />
<telerik:RadButton Grid.Row="4"
Grid.Column="2"
Content="{Binding PredictedSwapLocalisation}"
Click="PredictedShortButton_OnClick"
IsEnabled="{Binding PredictionsAvailable}"
AutomationProperties.AutomationId="PredictedShortButtonID"
x:Name="PredictedShortButtonID"
Margin="2"/>
<telerik:RadButton Grid.Row="4"
Grid.Column="4"
Content="{Binding PredictedSwapLocalisation}"
Click="PredictedLongButton_OnClick"
IsEnabled="{Binding PredictionsAvailable}"
AutomationProperties.AutomationId="PredictedLongButtonID"
x:Name="PredictedLongButtonID"
Margin="2"/>
<Border Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="5" BorderThickness="0, 1, 0, 0" Margin="0, 10, 0, 10" BorderBrush="LightGray" />
</Grid>
<Grid Grid.Row="1">
<ScrollViewer HorizontalAlignment="Left" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Name="ScrollViewer" ScrollChanged="ScrollViewer_OnScrollChanged">
<Grid>
<Grid.Resources>
<DataTemplate x:Key="RowsTemplate">
<Grid x:Name="TemplateGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" IsChecked="{Binding IsChecked}" VerticalAlignment="Center" Margin="5" IsEnabled="{Binding Editable}"
Command="{Binding Path=DataContext.CheckBoxChangedCommand, ElementName=Grid}" CommandParameter="{Binding}" />
<TextBlock Grid.Column="1" Text="{Binding Layer}" VerticalAlignment="Center" Margin="5" />
</Grid>
<TextBox Grid.Column="1"
Text="{Binding ShortDisplayValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding Editable}"
Width="80"
Margin="5"
TextChanged="ShortValueTextbox_TextChanged"
KeyDown="FirstUIElement_OnKeyDown"
LostFocus="FirstUIElement_OnLostFocus" />
<telerik:RadButton Grid.Column="2"
Command="{Binding Path=DataContext.SetSinglePredictedShortCommand, ElementName=Grid}"
CommandParameter="{Binding}"
IsEnabled="{Binding Editable}"
Visibility="{Binding Visible}" HorizontalContentAlignment="Left"
Margin="2">
<telerik:RadButton.Content>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Label Background="{Binding ConfidenceBrush}" Foreground="{Binding ConfidenceForegroundBrush}" Height="20" Width="20" Content="{Binding ConfidenceCharacter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0"></Label>
<TextBlock Text="{Binding ShortButton}" />
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
<TextBox Grid.Column="3"
Text="{Binding LongDisplayValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding Editable}"
Width="80"
Margin="5"
TextChanged="ShortValueTextbox_TextChanged"
KeyDown="SecondUIElement_OnKeyDown"
LostFocus="SecondUIElement_OnLostFocus" />
<telerik:RadButton Grid.Column="4"
Command="{Binding Path=DataContext.SetSinglePredictedLongCommand, ElementName=Grid}"
CommandParameter="{Binding}"
IsEnabled="{Binding Editable}"
Visibility="{Binding Visible}" HorizontalContentAlignment="Left"
Margin="2">
<telerik:RadButton.Content>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Label Background="{Binding ConfidenceBrush}" Foreground="{Binding ConfidenceForegroundBrush}" Height="20" Width="20" Content="{Binding ConfidenceCharacter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0"></Label>
<TextBlock Text="{Binding LongButton}" />
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
</Grid>
</DataTemplate>
</Grid.Resources>
<ItemsControl ItemTemplate="{StaticResource RowsTemplate}" ItemsSource="{Binding Rows}" />
</Grid>
</ScrollViewer>
</Grid>
<Border Grid.Row="2" BorderThickness="0, 1, 0, 0" Margin="0, 0, 0, 10" BorderBrush="LightGray" />
<Grid Grid.Row="3" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="A" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<telerik:RadButton Grid.Row="0" Grid.Column="0"
Content="{Binding SwapAllLocalisation}"
Click="SwapAllButton_OnClick"
IsEnabled="{Binding ScalesExist}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="0" Grid.Column="1"
Content="{Binding SetAllPredictedLocalisation}"
Click="SetAllPredictedButton_OnClick"
IsEnabled="{Binding PredictionsAvailable}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="0" Grid.Column="2"
Content="{Binding ResetLocalisation}"
Click="ResetButton_OnClick"
IsEnabled="{Binding ScalesExist}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="0" Grid.Column="3"
Content="{Binding ArtworkRevisionsLocalisation}"
Click="ArtworkRevisionsButton_OnClick"
HorizontalAlignment="Center"
IsEnabled="{Binding ArtworksButtonEnabled}"
Visibility="{Binding ArtworksButtonVisible, Converter={ StaticResource BooleanToVisibilityHiddenOnFalseConverter}}"
Margin="2"/>
<telerik:RadButton Grid.Row="1" Grid.Column="0"
Content="{Binding ImportLocalisation}"
Click="ButtonImport_Click"
IsEnabled="{Binding ScalesExist}"
ContextMenu="{StaticResource ImportContextMenu}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="1" Grid.Column="1"
Content="{Binding StackupImportLocalisation}"
Click="ButtonImportFromStackup_OnClick"
ContextMenu="{StaticResource ImportFromStackupContextMenu}"
IsEnabled="{Binding CanImportFromStackup}"
Visibility="{Binding ImportFromStackupEnabled, Converter={StaticResource BooleanToVisibilityConverter}}"
HorizontalAlignment="Center"
Margin="2"/>
<ItemsControl Grid.Row="1" Grid.Column ="2" Grid.ColumnSpan="2" ItemsSource="{Binding ScalingImportExportMetaData.ScalingExportTypes}" ItemTemplate="{StaticResource ExportButtonTemplate}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Grid Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Grid.ColumnSpan="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock Text="{Binding SingleCoresLocalisation}" VerticalAlignment="Center"/>
<RadioButton IsChecked="{Binding UseSingleCores}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBlock Text="{Binding IndividualCopperLocalisation}" VerticalAlignment="Center"/>
<RadioButton IsChecked="{Binding UseSingleCores, Converter={ StaticResource BooleanInvertConverter}}" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
</Grid>
</Grid>
</ScrollViewer>
<Grid Grid.Column="1">
<Grid.Resources>
<converters:NonZeroDoubleToVisibilityConverter x:Key="NonZeroDoubleToVisibilityConverter" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="B"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition SharedSizeGroup="C"></RowDefinition>
<RowDefinition SharedSizeGroup="D"></RowDefinition>
</Grid.RowDefinitions>
<ScrollBar Grid.Row="1" Minimum="0" SmallChange="1" LargeChange="10"
ViewportSize="{Binding ViewportHeight, ElementName=ScrollViewer}"
Maximum="{Binding ScrollableHeight, ElementName=ScrollViewer}"
Scroll="ScrollBar_OnScroll" Name="ScrollBar"
Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Maximum, Converter={StaticResource NonZeroDoubleToVisibilityConverter}}" />
</Grid>
</Grid>
</infrastructure:Plugin>
I want do some things with my listview on my UWP project:
When a item of the listview is selected I want the entire row selected, also the subitems (cells) on the row should be not selectable.
I was trying with Fullrowselect but seem is not longer availiable in uwp.
my current xaml is:
<ListView x:Name="ListView1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,164,0,0" BorderBrush="Black" BorderThickness="1" Background="WhiteSmoke" Visibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid Padding="0" Margin="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<TextBox x:Name="TextBox_Item" Grid.Column="0" Text="{Binding Path=Item}" TextWrapping="Wrap" BorderBrush="Black" BorderThickness="1.5" IsReadOnly="True" TextAlignment="Left"/>
<TextBox x:Name="TextBox_Name" Grid.Column="1" Text="{Binding Path=Name}" TextWrapping="Wrap" BorderThickness="1.5" BorderBrush="Black" IsReadOnly="True" TextAlignment="Left"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Any help is appreciated.
There's a property called "IsHitTestVisible, try changing it to false on your textboxes.
<ListView x:Name="ListView1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,164,0,0" BorderBrush="Black" BorderThickness="1" Background="WhiteSmoke" Visibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid Padding="0" Margin="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<TextBox x:Name="TextBox_Item" Grid.Column="0" Text="{Binding Path=Item}" TextWrapping="Wrap" BorderBrush="Black" BorderThickness="1.5" IsReadOnly="True" TextAlignment="Left" IsHitTestVisible="False"/>
<TextBox x:Name="TextBox_Name" Grid.Column="1" Text="{Binding Path=Name}" TextWrapping="Wrap" BorderThickness="1.5" BorderBrush="Black" IsReadOnly="True" TextAlignment="Left" IsHitTestVisible="False"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Here I have a ListBox:
<ListBox Name="listbox1" ItemsSource="{Binding Area}" Grid.Column="0" Grid.Row="0" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Green" BorderThickness="2" Margin="5" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0" Margin="2">
<TextBox PreviewTextInput="minMaxPreviewInput" IsReadOnly="{Binding AutoChange}" Text="{Binding MinIntValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="30" DockPanel.Dock="Right" TextAlignment="Right"/>
<TextBlock Text="Minimum Value" DockPanel.Dock="Left"/>
</DockPanel>
<DockPanel Grid.Row="1" Grid.Column="0" Margin="2">
<TextBox PreviewTextInput="minMaxPreviewInput" IsReadOnly="{Binding AutoChange}" Text="{Binding MaxIntValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="30" DockPanel.Dock="Right" TextAlignment="Right"/>
<TextBlock Text="Maximum Value" DockPanel.Dock="Left"/>
</DockPanel>
<DockPanel Grid.Row="2" Grid.Column="0" Margin="2">
<TextBlock Text="{Binding AreaName}" FontSize="20" DockPanel.Dock="Left"/>
<TextBlock Text=":" FontSize="20" DockPanel.Dock="Left"/>
<TextBlock Text="{Binding Start}" FontSize="20" DockPanel.Dock="Left"/>
<CheckBox FlowDirection="RightToLeft" DockPanel.Dock="Right" IsChecked="{Binding AutoChange, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TextBlock FlowDirection="LeftToRight" Text="Auto-Change:" />
</CheckBox>
</DockPanel>
<Border BorderBrush="Blue" BorderThickness="1" Grid.Column="1" Grid.RowSpan="3" Margin="5">
<Canvas Name="canvas1" >
<Canvas.LayoutTransform>
<ScaleTransform ScaleX="1" ScaleY="-1" CenterX=".5" CenterY=".5" />
</Canvas.LayoutTransform>
<Polyline Points="{Binding SegmentPoints}" Stroke="Black" StrokeThickness="1"/>
</Canvas>
</Border>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Everything works as great. I'm having problem accessing the Canvas size. How can I access it? Listbox.ActualHeight and ListBox.ActualWidth are bigger than the Canvas, and I need to get the Canvas exact size.
Thanks for the help in advance.
As you are trying to base the value of other bound values on the Canvas size, use OneWayToSource mode on a Binding for ActualWidth and ActualHeight to some properties on your ViewModel.
This will push the values from the control into your ViewModel allowing you to adjust the values in SegmentPoints so that they are scaled correctly according to the Canvas size.
Hi buddies :) I am working on a wpf app which deals with groupboxes and wrap panel. Looking at the title, it seems to be simple but after dynamically generating set of groupboxes I am finding it difficult. Here is the scenario:
I have 2 xaml files in my project. One is CodecView.xaml and CodecWidgetView.xaml. I have dynamically generated 4 groupboxes on startup as follows:
CodecView.xaml:
<UserControl.Resources>
<DataTemplate x:Key="CWDataTemplate">
<WrapPanel>
<TextBlock Text="{Binding Description}" Margin="0,0,0,0"/>
<local:CodecWidgetView Margin="5,10,5,5"/>
</WrapPanel>
</DataTemplate>
</UserControl.Resources>
<Grid Grid.Row="0" >
<Grid Name="NumberofCodecs" >
<ItemsControl ItemTemplate="{StaticResource CWDataTemplate}" ItemsSource="{Binding CodecWidgets}"/>
</Grid>
</Grid>
CodecWidgetView.xaml:
<Grid>
<GroupBox Height="Auto" HorizontalAlignment="Stretch" Margin="5,5,5,5" Name="groupBox1" VerticalAlignment="Stretch" Width="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ToggleButton Name="FrequencyBox" Content="Master" Grid.Column="1" Height="25" Width="50" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0" />
<ComboBox Grid.Column="2" ItemsSource="{Binding ModesList}" SelectedItem="{Binding SelectedModesList, Mode=OneWayToSource}" SelectedIndex="2" Height="23" HorizontalAlignment="Center" Margin="0,0,0,0" Name="comboBox2" VerticalAlignment="Center" Width="80" />
<ComboBox Grid.Column="0" ItemsSource="{Binding FrequencyList}" SelectedItem="{Binding SelectedFrequencyList, Mode=OneWayToSource}" SelectedIndex="0" Height="23" HorizontalAlignment="Center" Margin="0,0,0,0" Name="comboBox1" VerticalAlignment="Center" Width="80" />
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Command="{Binding OneSixBitCommand}" Margin="0" Content="16 Bit" Name="OneSixBit" Height="25" Width="45" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Command="{Binding TwoZeroBitCommand}" Margin="0" Content="20 Bit" Name="TwoZeroBit" Height="25" Width="45" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Command="{Binding TwoFourBitCommand}" Margin="0" Content="24 Bit" Name="TwoFourBit" Height="25" Width="45" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" />
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Command="{Binding ThreeTwoBitCommand}" Margin="0" Content="32 Bit" Name="ThreetwoBit" Height="25" Width="45" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<Grid Grid.Row="2">
<Label Name="BitDelay" Content="Bit Delay" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,205,0" Height="25" Width="55" />
<Slider Height="23" HorizontalAlignment="Center" Minimum="0.0" Maximum="255.0" TickFrequency="1.0" Margin="95,0,0,0" Name="bitdelayslider" VerticalAlignment="Center" Width="160" />
<TextBox Name="BitDelayValue" IsReadOnly="True" Text="{Binding ElementName=bitdelayslider,Path=Value, StringFormat=0.0}" Width="40" Height="20" Margin="0,0,110,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<Grid Grid.Row="3">
<Label Name="DBGain" Content="DB Gain" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,205,0" Height="25" Width="55" />
<TextBox Name="DBGainValue" IsReadOnly="True" Text="{Binding ElementName=dbgainslider,Path=Value, StringFormat=0.0}" Width="40" Height="20" Margin="0,0,110,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Slider Height="23" HorizontalAlignment="Center" Minimum="0.0" Maximum="59.5" TickFrequency="0.5" Margin="95,0,0,0" Name="dbgainslider" VerticalAlignment="Center" Width="160" />
</Grid>
</Grid>
</GroupBox>
</Grid>
CodecViewModel.cs: is a viewmodel class of CodecView.xaml
public ObservableCollection<CodecWidgetViewModel> CodecWidgets { get; set; }
public CodecViewModel()
{
CodecWidgets = new ObservableCollection<CodecWidgetViewModel>();
CodecWidgets.Add(new CodecWidgetViewModel { Description = "Location 8 - Dig Mic A" });
CodecWidgets.Add(new CodecWidgetViewModel { Description = "Location 9 - Dig Mic B" });
CodecWidgets.Add(new CodecWidgetViewModel { Description = "Location 10 - PCM A 3P3V" });
CodecWidgets.Add(new CodecWidgetViewModel { Description = "Location 11 - PCM B 3P3V" });
}
CodecWidgetViewModel.cs: is a viewmodel class of CodecWidgetView.xaml
private string _description;
public string Description
{
get
{
return _description;
}
set
{
_description = value;
OnPropertyChanged("Description");
}
}
This on startup dynamically generates 4 groupboxes one below the other. Since my windowsize is minheight = 300 and minwidth = 300, I have set scrollviewer. Since I have used Wrappanel, When i stretch it, it should behave as expected. That's when width is stretched 2nd groupbox should go to the right side of 1st row and same happens below.
On Startup:
When Width is Stretched:
Expected behaviour:
Thus looking at the expected behaviour, I want to achieve how wrappanel behaves :) Even though I have used wrappanel but it doesn't wrk as expected. Please help :)
You have used a WrapPanel as the panel of each individual item in the ItemsSource, which is not doing what you want.
Instead you have to explicitly tell the ItemsControl to use a WrapPanel as the panel for all of its children.
<ItemsControl ItemTemplate="{StaticResource CWDataTemplate}" ItemsSource="{Binding CodecWidgets}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
I have difficulty accessing a grid or its rows(within a ListBox), despite defining the grid's or row's name. I intend to set a new MaxHeight to one of its rows when some parameter is passed in from a SharePoint browsable property to the Silverlight control.
How may i achieve the desired effect? Binding perhaps?
# Page.xaml:
<ListBox ItemsSource="{Binding}" DataContext="" x:Name="NewsList" SelectionChanged="NewsList_SelectionChanged" SelectionMode="Single" Width="580" Height="360" VerticalAlignment="Top" HorizontalAlignment="Center" >
<ListBox.ItemTemplate>
<DataTemplate >
<Grid Height="110" Width="540" x:Name="StaffNewsBodyHeight">
<Grid Height="110" Width="540">
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="{Binding StaffNewsBodyHeight}" />
<RowDefinition Height="15" />
</Grid.RowDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="82" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border CornerRadius="2" BorderThickness="2" BorderBrush="Gray" Height="82" Width="82" Background="LemonChiffon" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.RowSpan="3" Grid.Column="0" >
<Image Source="{Binding NewsThumbnail}" Style="{StaticResource ThumbNailPreview}" />
</Border>
<TextBlock x:Name="NewsTitle" FontFamily="Arial" FontWeight="bold" TextDecorations="Underline" Text="{Binding Title}" Style="{StaticResource TitleText}" Grid.Row="0" Grid.Column="1"/>
<TextBlock x:Name="NewsBody" FontFamily="Arial" Text="{Binding NewsBody}" Margin="5" Style="{StaticResource DescriptionBlock}" Grid.Row="1" Grid.Column="1" />
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Margin="3,3,3,3">
<TextBlock Text="Published By:" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />
<TextBlock Text="{Binding PublishedBy}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />
<TextBlock Text="{Binding DatePublished}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
# Page.xaml.cs:
if (!string.IsNullOrEmpty(_setLength))
{
StaffNews test = new StaffNews();
//assign new height to gridrow of NewsBody
if (_setLength.Contains("_3"))
test.StaffNewsBodyHeight.Equals(200);
}
I believe that StaffNews is representing one item in your list, right?
In that case, to assign a value to a property, use:
test.StaffNewsBodyHeight = 200;
to replace the last line of your snippet.
[P.S. - StaffNewsBodyHeight is a dependency property defined in StaffNews, right?]