datatemplate

Silverlight how to promote selected item of listbox when using buttons within datatemplates

人盡茶涼 提交于 2019-12-08 10:28:07
问题 Within a Listbox control I have a Data Template which consists of text and a button. Given the nature of Silverlight/WPF when I click on the button within the listbox item the button event is trapped before the listbox item is selected. Therefore if I am trying to pass the record ID of the selected listbox item I am currently only able to do so by first clicking and selecting the listbox item and then clicking on the button. Is there a way to promote the selection of the listbox item so that

How to change the menu content by using DataTrigger in XAML?

若如初见. 提交于 2019-12-08 07:04:36
问题 I have two kinds of menu items according to the login. So, by using the property in the ViewModel Class bool IsAdmin {get; set;} I have to change the menu item content.I am not familiar with data template. I want to define all the menu items in the xaml itself (might be using the data templates). How we can bind the differnt menu items by using the data trigger. Can anyone can give a smaller example for this. using only this property and no c# codes. 回答1: Use ContentControl and Styles for max

Silverlight - Access the Layout Grid's DataContext in a DataGrid CellTemplate's DataTemplate?

南笙酒味 提交于 2019-12-08 06:11:11
问题 I am using Silverlight 3 to develop an application. In my app, I have a layout Grid (named "LayoutGrid") in which I have a DataGrid (named "PART_datagrid") with DataGridTemplateColumns. The LayoutGrid is set a DataContext in which there is a Ladders list as a property. This Ladders list is set as the ItemsSource for the PART_datagrid. <Grid x:Name="LayoutRoot"> <DataGrid x:Name="PART_datagrid" ItemsSource="{Binding Ladders}"> ... <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate>

WPF - Retrieve Child DataTemplate Control From Custom ListBoxItem

断了今生、忘了曾经 提交于 2019-12-08 05:23:20
问题 In my application, I have a ListBox with a custom DataTemplate. The XAML is as follows: <ListBox Name="lstTasks"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" VerticalAlignment="Top"> <CheckBox Name="chkIsChecked" VerticalAlignment="Top" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}"/> <RichTextBox Name="rtbTask" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="450" BorderBrush="{DynamicResource {x:Static SystemColors

WPF - Retrieve Child DataTemplate Control From Custom ListBoxItem

不问归期 提交于 2019-12-08 03:54:40
In my application, I have a ListBox with a custom DataTemplate. The XAML is as follows: <ListBox Name="lstTasks"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" VerticalAlignment="Top"> <CheckBox Name="chkIsChecked" VerticalAlignment="Top" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}"/> <RichTextBox Name="rtbTask" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="450" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveCaptionTextBrushKey}}" Margin="0,0,0,10"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> I use a

CellTemplateSelector won't choose template automatically

左心房为你撑大大i 提交于 2019-12-08 02:56:33
问题 I have two templates for DataGridTemplateColumn <DataTemplate x:Key="firstTemplate"> <UniformGrid Grid.Column="1" Columns="2"> <Label Background="{Binding Path=Color, Converter={StaticResource gradientBrush}}" Content="{Binding Path=Value}" Style="{StaticResource WhiteCellLabelStyle}" Visibility="Visible" /> </UniformGrid> </DataTemplate> <DataTemplate x:Key="secondTemplate"> <UniformGrid Grid.Column="1" Columns="{Binding Converter={StaticResource getColumnsAmount}}"> <Label Background="

Why using UserControl inside DataTemplate is slower than direct xaml?

ⅰ亾dé卋堺 提交于 2019-12-08 02:04:16
问题 I have code as this one: <ListBox ItemsSource="{Binding Items}"> <ListBox.ItemTemplate> <DataTemplate DataType="{x:Type local:MyViewModel}"> <!-- xaml is typed here directly --> <Border> ... </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox> And xaml inside the DataTemplate is big (more than 200 lines). I want to move xaml which is inside the DataTemplate into a separate UserControl to make it easier to edit and maintain. I do next: <ListBox ItemsSource="{Binding Items}"> <ListBox

Custom WPF ListView with Style (using DataTemplate) - how do I add headers?

二次信任 提交于 2019-12-08 01:04:25
问题 I have the following code DataTemplate for rows <!-- Template for each item in ListView --> <DataTemplate x:Key="ItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="25"/> <ColumnDefinition Width="90"/> <ColumnDefinition Width="325"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type l:ItemsView}}, Path=ParentColumnWidth}"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/> <

Best way to stretch WPF ListBox.ItemTemplate's contents to the width of ListBoxItem

ぐ巨炮叔叔 提交于 2019-12-07 16:41:05
问题 I know this may be duplicate, but I haven't found a best solution. I simply come across a issue of using ListBox.ItemTemplate, I want the content Grid to HorizontalAlignment=" Stretch "(not work). So I tried to bind the Grid' Width to the ListBoxItem , but the last item behaves strangely. If bind to the Width of ListBox , there will be a scrollbar, although a converter may solve it, I think there must be some more simple and elegant solution. Codebehind: public partial class MainWindow :

Binding datatemplate to ContentControl's Content

做~自己de王妃 提交于 2019-12-07 12:13:00
问题 How to bind textbox text property, within datatemplate, to ContentControl Content property? (Without bindng via ElementName) This is my code( that doesn't work): <Window.Resources> <DataTemplate x:Key="Temp"> <TextBox TextWrapping="Wrap" Text="{TemplateBinding Content}" Height="20" Width="Auto"/> </DataTemplate> </Window.Resources> <Grid> <ContentControl ContentTemplate="{DynamicResource Temp}" Content="1"/> </Grid> 回答1: Use a relative source binding: Text="{Binding RelativeSource=