datatemplate

How to bind to parent DataTemplate from within an ItemsControl.ItemTemplate

青春壹個敷衍的年華 提交于 2019-12-06 11:46:05
问题 I have a container type control which contains a number of items. The container control has a DataTemplate defined which also contains a ItemsControl with a DataTemplate for the item. The items however need to bind to something from the container control. A simplified example is given below: <DataTemplate DataType="{x:Type ContainerType}"> <!-- Display of the container stuff--> <ItemsControl ItemsSource="{Binding Items, Mode=OneWay}"> <ItemsControl.ItemTemplate> <DataTemplate DataType="{x

DataGrid ColumnWidth Property ignored in DataTemplate for row details

╄→гoц情女王★ 提交于 2019-12-06 10:49:08
问题 This is the UserControl that displays the details from my application and as you can see the ColumnWidth Property is explicit set to * . I also tried to set the Width property from the DataGridTextColumn . <UserControl x:Class="WpfUserInterface.MyDetailsView" 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

How do I bind to this custom dependency property?

末鹿安然 提交于 2019-12-06 10:17:27
I have a DependencyProperty in my custom UserControl that looks like this: public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.Register("ColumnWidth", typeof(int), typeof(CallBoard), new PropertyMetadata(150)); public int ColumnWidth { get { return (int)GetValue(ColumnWidthProperty); } set { SetValue(ColumnWidthProperty, value); } } In Expression Blend 3, I have this: <UserControl 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"

Problem with SelectedItem of WPF Editable ComboBox with DataTemplate

倾然丶 夕夏残阳落幕 提交于 2019-12-06 07:29:41
问题 I’m having the following issue with WPF ComboBox : XAML: <Window.Resources> <ResourceDictionary> <DataTemplate DataType="{x:Type this:Data}"> <ComboBox IsTextSearchEnabled="False" IsEditable="True" Text="{Binding Value}" ItemsSource="{Binding Menu}"/> </DataTemplate> </ResourceDictionary> </Window.Resources> <StackPanel> <ContentControl Content="{Binding}"/> <Button Click="ChangeData_Click">Change Data</Button> </StackPanel> Code behind: public Window1() { InitializeComponent(); DataContext =

Add data-binding for DataGridTemplateColumn created in code

久未见 提交于 2019-12-06 04:37:30
问题 The question: Is there a way to define a DataTemplate in XAML and instantiate it in code (rather than retrieve singleton by FindResource ) and modify its VisualTree before sending to where a DataTemplate is required such as DataGridTemplateColumn.CellTemplate ? Background: I am displaying a 2-dimensional array data[][] in a DataGrid by adding DataGridTemplateColumn columns on my own and there is a DataTemplate defined in XAML that knows how to present each element in the array. However the

GridViewColumn CellTemplate Code Behind

青春壹個敷衍的年華 提交于 2019-12-06 04:16:13
问题 I have a listView that I construct at run-time, i.e. the columns are not known at compile-time. I would like to apply a DataTemplate to the cells such that the TextAlignment property is TextAlignment.Right. When creating the columns: foreach (var col in dataMatrix.Columns) { gridView.Columns.Add( new GridViewColumn { Header = col.Name, DisplayMemberBinding = new Binding(string.Format("[{0}]", count)), CellTemplate = getDataTemplate(count), }); count++; } private static DataTemplate

'Default' text for templated combo box

谁说胖子不能爱 提交于 2019-12-06 04:02:54
问题 I have a combo box that is based on a data template the includes check boxes like such: <ComboBox x:Name="cboComplex" Text="Select days..."> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding Path=IsSelected}" Width="20"/> <TextBlock Text="{Binding DayOfWeek}" Width="100" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> The problem I'm having is that I'd like the combobox to display "Select days..." and then show the

WPF Ribbon: DataTemplate causes BindingExpression path error

半世苍凉 提交于 2019-12-06 03:38:45
问题 I've run into a small problem using the WPF RibbonControl (October 2010 version). My idea was to bind the ItemsSource property of a RibbonGroup to my viewmodel, and use a DataTemplate to create RibbonButtons as needed. This works, but it causes a binding error (one for each button) when you show the window: System.Windows.Data Error: 40 : BindingExpression path error: 'IsDropDownOpen' property not found on 'object' ''RibbonContentPresenter' (Name='PART_ContentPresenter')'. BindingExpression

Wrap something around each item in an ItemsControl

岁酱吖の 提交于 2019-12-06 02:52:18
问题 Let's say I have a collection of objects of different classes. Each class has its UserControl DataTemplated in a resource file. Now I want to use ItemsControl to display the collection, but I want an Border or Expander around each item. I would expect something like this to work: <ItemsControl ItemsSource="{Binding MyObjects}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate>

Binding datatemplate to ContentControl's Content

依然范特西╮ 提交于 2019-12-06 00:53:44
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> H.B. Use a relative source binding: Text="{Binding RelativeSource={RelativeSource AncestorType=ContentControl}, Path=Content}" Edit: I probably should note that, in terms of what