datatemplate

Access control within datatemplate

送分小仙女□ 提交于 2019-12-23 18:49:37
问题 This is XAML: <Window.Resources> <DataTemplate x:Key="Temp"> <DockPanel Width="Auto" Background="White" LastChildFill="False"> <TextBox Name="txtBox" TextWrapping="Wrap" DockPanel.Dock="Left" Text="{Binding RelativeSource={RelativeSource AncestorType=ContentControl}, Path=Content}" Height="20" Width="100"/> <StackPanel Orientation="Vertical"> <RadioButton Content="Option1" HorizontalAlignment="Left" Height="16" Width="112" Click="RadioButton_Click" /> </StackPanel> </DockPanel> </DataTemplate

How to get ContentControl to resolve DataTemplate

▼魔方 西西 提交于 2019-12-23 14:21:51
问题 Why does this not resolve the datatemplate? <Window.Resources> <DataTemplate DataType="system:DateTime" > <Grid Background="Aqua"> <TextBlock Text="{Binding Day}"></TextBlock> </Grid> </DataTemplate> </Window.Resources> <Grid> <ContentControl Content="{x:Static system:DateTime.Now}"/> </Grid> Writing a TemplateSelector feels like an overkill. 回答1: DataType design suggests the presence of a directive x:Type like that: <DataTemplate DataType="{x:Type system:DateTime}"> <Grid Background="Aqua">

DataTemplate.DataType = Collection<Entity>?

我是研究僧i 提交于 2019-12-23 07:47:52
问题 Is there a way to create a data template that handles a list of items? I have Contact.Phones ( EntityCollection<Phone> ) and I want the data template to handle the list - add remove edit etc. Is there a way to set the DataType property of the DataTemplate to generic EntityCollection<Phone> ? 回答1: Wrap your generic list in a new class, which subclasses your generic list without adding anything. This makes it possible to bind to the list from XAML. This is described here: Can I specify a

Is it possible to pass multiple resources into a DataTemplate?

混江龙づ霸主 提交于 2019-12-23 06:05:31
问题 I want to reuse a DataTemplate for multiple columns in a ListView. Given the two XmlDataProvider I select values from the second by using the selected item in the first. This works if I specify the additional resource in the DataTemplate . But this forces me to duplicate the code of the DataTemplate and just exchange the addtional resource. What I would like to do is this: <Window x:Class="LayoutTests.Window2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http:/

WPF DataTemplate Textblock binding

左心房为你撑大大i 提交于 2019-12-23 03:51:59
问题 I have a listbox of Students and the datatemplate for list item. The DataTemplate has a text block named tb. I want to set this textblock to be binded to Name property. How can I do it in xaml form outside? (Not from the datatemplate) <ListBox ItemsSource="{Binding l}" ItemTemplate="{Binding DataTemplate_L}" Margin="12,70,0,0"> </ListBox> Thank you 回答1: If I understand you correctly, you're asking how you set the databinding for the textblock, that is currently in your DataTemplate? You can't

Access UniformGrid ItemTemplate programmatically

▼魔方 西西 提交于 2019-12-23 03:33:19
问题 I'm trying to build a bingo game simulator using WPF to learn more about WPF, and I'm having trouble figuring out how to change an <ItemsControl> template programmatically. I'm only using the default WPF Application from VS 2010, so I have a MainWindow.xaml, App.xaml and MainWindow.xaml.cs. The reason I want to access the <ItemTemplate> , is to change the bound template if that bingo number comes up as chosen. I've tried this possible solution in my code behind file, but I don't think that

Resize WPF ListBox selection box

自作多情 提交于 2019-12-23 02:36:12
问题 For a project I have implemented a small IntelliSense like control which is nothing than a ListBox . Its DataTemplate consist of a StackPanel holding one Image and one TextBlock . Nothing else. As you can see in the first screenshot of my control, the selection box of the ListBox selects the whole item (which usually is exactly what one would expect): However my "stolen" icons from VS11 are low-quality so I wanted to adjust the selection like Visual Studio does: You can see that only the text

In the built-in WPF DataGrid, can I set the datasource for a DataGridTemplateColumn?

筅森魡賤 提交于 2019-12-22 16:55:11
问题 In this hypothetical example, imagine I have an object FooSet that has five properties Foo1, Foo2, Foo3 Foo4 and Foo5 all of which are type Foo which itself has several properties. Finally, I have a DataTemplate called FooTemplate that knows how to display objects of type Foo in a graphical way. Now when using the built-in DataGrid, ItemsSource is a collection of FooSet objects. What I want to do is set up five templated columns that all use the FooTemplate data template. However, the

Styling a Textblock autogenerated in a ContentPresenter

牧云@^-^@ 提交于 2019-12-22 07:05:15
问题 As I saw, a lot of people ran into this exact problem but I can't understand why my case is not working and it is starting to drive me crazy. Context: I have a DataGrid which is to be colored according to the values of each cell. Hence, I have a dynamic style resolving the actual template to be used for each cell. Backgrounds now work accordingly. New problem: when I have a dark background, I want the font color to be white and the font weight to be bold so the text is correctly readable. And

Why can't a DataTemplate bind to an interface when that DataTemplate was explicitly returned from a DataTemplateSelector?

牧云@^-^@ 提交于 2019-12-22 04:57:23
问题 I've created a DataTemplateSelector which is initialized with a collection of known interfaces. If an item passed into the selector implements one of those interfaces, the associated data template is returned. First, here's the ICategory interface in question... public interface ICategory { ICategory ParentCategory { get; set; } string Name { get; set; } ICategoryCollection Subcategories { get; } } Here's the DataTemplateSelector which matches based on a base class or interface rather than