datatemplate

in WPF I need to have a collection of a collection of drawing objects

天大地大妈咪最大 提交于 2019-12-31 04:22:07
问题 I have a WPF project that draws several things in a panel. For the next release I need to add another type of thing to draw in addition to the existing things. Currently I have a grid that contains an ItemsControl which contains an ItemsPanel and an ItemsSource. The existing ItemsSource looks something like this: <ItemsControl.ItemsSource> <CompositeCollection> <CollectionContainer Collection="{Binding Source={StaticResource MainWindowResource}, Path=DottedLines, Mode=OneWay}"/>

Problems with XamlReader generating DataTemplate

别等时光非礼了梦想. 提交于 2019-12-30 19:52:08
问题 I'm trying to implement the code below in my WPF project in order to generate DataTemplates on the fly for a DataGrid with dynamic columns. I found the code on StackOverflow here public DataTemplate Create(Type type) { return (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""> <" + type.Name + @" Text=""{Binding " + ShowColumn + @"}""/> </DataTemplate>" ); } However, on the XamlReader.Load code, I get the error "cannot convert from 'string' to

Binding(Converter) in Code Behind

Deadly 提交于 2019-12-30 04:58:06
问题 <local:LabelTemp x:Key="labelTemplate"/> <DataTemplate x:Key="labelTemp"> <TextBlock Text="{Binding Converter={StaticResource labelTemplate},Path=Item.Items}"/> </DataTemplate> Can anyone help me how to write the above Xaml code into Code Behind C#. Im using this code into Pie Chart LabelTemplate. 回答1: I don't what is the binding source, or how the Pie Chart LabelTemplate (converter) look like. The best I can come up with that much information is the following: public class LabelTemplate :

Find an element in DataTemplate applied to TabItem

巧了我就是萌 提交于 2019-12-29 09:59:13
问题 I got a problem trying to find an element declared in DataTemplate, that after was applied like a ContentTemplate to TabItem object. I saw that there is already some solutions in regard of this problem, but no one of them actually works in my case, and I would like to understand why (obviously I make mistake in some place) Here is a sample code: <DataTemplate x:Key="TabItemDataTemplate"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="templateGrid"> <Grid.RowDefinitions>

Styling WPF ComboBox items

社会主义新天地 提交于 2019-12-29 08:27:33
问题 I have a very simple WPF application which displays a ComboBox which binds to a list of classes which represent people. Each 'Person' object has a Name string field, and a Sex enum. I would like the ComboBox to display a drop-down of the various people's Name field, but for each line to be styled according to the Sex field, for example, blue for males, pink for females. Can anyone tell me what I am doing wrong? Here is the XML: <Window x:Class="ComboBoxColour.MainWindow" xmlns="http://schemas

How to access any control inside Hubsection Datatemplate in Windows 8.1 store

谁都会走 提交于 2019-12-29 07:35:07
问题 Please tell me how to access flipview control inside Hubsection * DataTemplate * 回答1: I don't know if you managed to solve your problem already. If you didn't here is how. private DependencyObject FindChildControl<T>(DependencyObject control, string ctrlName) { int childNumber = VisualTreeHelper.GetChildrenCount(control); for (int i = 0; i < childNumber; i++) { DependencyObject child = VisualTreeHelper.GetChild(control, i); FrameworkElement fe = child as FrameworkElement; // Not a framework

How to Automatically Use a DataTemplate Based on ContentControl's Current Content's DataType

大兔子大兔子 提交于 2019-12-29 04:30:15
问题 When I attempt to specify multiple DataTemplates for use by a ContentControl so that the correct one (based on Type) is used, I end up with Content that is simply the Content's ToString() value. <ContentControl DataContext="{Binding MyTreeRootViewModels}" Content="{Binding /, Path=CurrentlySelectedTreeViewModel}"> <ContentControl.Resources> <DataTemplate DataType="x:Type vm:TypeAViewModel"> <StackPanel> <local:TypeAUserControl /> </StackPanel> </DataTemplate> <DataTemplate DataType="x:Type vm

How do I make a WPF data template fill the entire width of the listbox?

狂风中的少年 提交于 2019-12-28 04:54:11
问题 I have a ListBox DataTemplate in WPF. I want one item to be tight against the left side of the ListBox and another item to be tight against the right side, but I can't figure out how to do this. So far I have a Grid with three columns, the left and right ones have content and the center is a placeholder with it's width set to "*". Where am I going wrong? Here is the code: <DataTemplate x:Key="SmallCustomerListItem"> <Grid HorizontalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition/> <

How do I dynamically bind and statically add MenuItems?

北慕城南 提交于 2019-12-28 03:40:08
问题 I'm binding the ItemsSource of my MenuItem to an ObservableCollection in my ViewModel. Here is my xaml: <MenuItem Header="_View" ItemsSource="{Binding Windows}"> <MenuItem.ItemContainerStyle> <Style> <Setter Property="MenuItem.Header" Value="{Binding Title}" /> </Style> </MenuItem.ItemContainerStyle> </MenuItem> This part works great, but now I also want to add some static MenuItems to the same View MenuItem, separated with a separator. Something like this, even though I know this won't work

Select ListBoxItem if TextBox in ItemTemplate gets focus

孤人 提交于 2019-12-28 03:06:15
问题 I have added a DataTemplate to a ListBox class to bind my collection to: <ListBox x:Name="lstEmails" Height="259" Margin="12,0,12,41" Width="276" SelectionChanged="lstEmails_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Label Visibility="Hidden" Content="{Binding ID}"></Label> <TextBox Width="200" Text="{Binding EmailAddress}"></TextBox> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> This does exactly what I want it to do.