datatemplate

ContentControl won't use DataTemplates

我怕爱的太早我们不能终老 提交于 2019-12-12 00:25:53
问题 I have two models that i want to represent as directories and files. The models both implement an interface which contains a property string Name {get;} . public interface INode { string Name { get; } string Path { get; } } public class Directory : INode { public Directory(string name, string path) { this.Name = name; this.Path = path; } public string Name { get; } public string Path { get; } } public class File : INode { public File(string name, string path) { this.Name = name; this.Path =

How to reference existing Resources from a XamlReader.Parse(xmlFragment) call

徘徊边缘 提交于 2019-12-11 23:25:16
问题 I have a situation in which I'm creating a custom DataTemplate using XamlReader.Parse(xamlString), where xamlString is the fragment which contains the DataTemplate: <DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <StackPanel Visibility="{Binding MyBinding, Converter={StaticResource boolToVisibilityConverter}}"> ... </StackPanel> </DataTemplate> As you can see, this DataTemplate has a reference to a static resource (the BooleanToVisibilityConverter). The call

WPF: Change DataTemplate for one change

随声附和 提交于 2019-12-11 20:56:00
问题 In my Wpf application, I've two datatemplates. DefaultDataTemplate and EditableDataTemplate. Xaml: <DataTemplate x:Key="DefaultDataTemplate" > <StackPanel Orientation="Horizontal" Width="596"> <TextBlock Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" TextWrapping="Wrap" Width="145"/> <TextBlock Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" TextWrapping="Wrap" Width="90"/> <TextBlock Text="{Binding StartTimeBinding}"

My UserControl isn't being rendered when used inside a DataTemplate

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 18:39:53
问题 I have a UserControl defined in MyUserControl.xaml. If I reference this directly from another control, then it displays correctly. For example: <Grid> <MyUserControl/> <Grid> works as expected. But if I try to use the UserControl in a DataTemplate it doesn't work. For example, if I have a DataTemplate like <DataTemplate> <MyUserControl/> <DataTemplate> nothing gets rendered. What's up? 回答1: Does your UserControl have a corresponding .xaml.cs file? This seems to happen when it doesn't. If you

Bind SelectedItem in a ListBox to CommandParameter in a ContextMenu

别等时光非礼了梦想. 提交于 2019-12-11 18:26:05
问题 Although this question is very similar to others posted, it has a few twist! I have an ObservableCollection of items in a ListBox and use a DataTemplate to display some of the collection members. However, I have a ContextMenu defined so I can execute DelegateCommands defined in my ViewModel using the Command parameter. All my Bindings are working up to here, except that I need to provide an argument for the Command in the ViewModel using CommandParameter of the item selected in the ListBox so

Changing label content programmatically from within a DataTemplate used in a DataGrid column header

守給你的承諾、 提交于 2019-12-11 18:17:06
问题 I'm dynamically creating DataGrid columns (based on an event from my ViewModel) and programmatically adding them to an existing DataGrid. Each column uses a generic HeaderTemplate by setting it to a DataTemplate that has been identified in the xaml. The DataTemplate contains two labels in which needs their content needs to be changed upon creation of the DataGrid column. How would this be done? I understand that the DataTemplate uses the ContentPresenter but I am having trouble accessing it

Access a named TextBox in the code behind from a ContentPresenter's DataTemplate

余生长醉 提交于 2019-12-11 17:41:53
问题 I am trying to get access to a named TextBox (textBoxAnswer) in the code behind of my WPF Page. The trouble is, because it is part of a DataTemplate , it is not auto-generated as a private member of the class, like it would be if I wasn't using the ContentPresenter + DataTemplate . (I am using the DataTemplate because I need to use DataTrigger s, not included in the example below). I have tried calling FindResource("textBoxAnswer") and FindName("textBoxAnswer") , but neither return anything.

How can I get the parent (Expander control in this case) of my DataTemplate in a Click Event?

∥☆過路亽.° 提交于 2019-12-11 17:26:05
问题 So I have this XAML as my UserControl. I have an Expander for each property I need to use. In the Header property of the Expander I've done binding to a DataTemplate to use a Image Button. What I need is to edit the fields inside the Expander (put them enabled) when I click the Image Button. But since it is inside of a DataTemplate I don't see the way to ask for it's "major parent" (Expander) and then ask the parent (Expander) to enable the fields. This is the code of my XAML (the variables

WPF datagrid XML binding displaying multiple Items in a cell using DataTemplate

筅森魡賤 提交于 2019-12-11 15:30:57
问题 I have a DataGrid which is as follows:: <wpfkit:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" Width="Auto" FrozenColumnCount="2" SelectionMode="Extended" CanUserAddRows="False" x:Name="CommonPEGrid" Loaded="CommonPEGrid_Loaded"> <wpfkit:DataGrid.DataContext> <XmlDataProvider Source="PE.xml" XPath="/Rows/Row"></XmlDataProvider> </wpfkit:DataGrid.DataContext> </wpfkit:DataGrid> I am binding it from XML to DataGrid. My XML is as follows:: <Rows> <Row Id="1"> <Devices> <Device

WP 8.1: DataTemplateSelector isn't working

不问归期 提交于 2019-12-11 10:04:39
问题 I've got a Windows Phone 8.1 Pivot App project . I'm trying to create DataTemplate's selection in a xaml listview but it fail. I can run the app but i got a break: global::System.Diagnostics.Debugger.Break(). Here is some code. My DataTemplateSelector namespace DMI { public class ExploreTemplateSelector : DataTemplateSelector { public DataTemplate FolderTemplate { get; set; } public DataTemplate DocumentTemplate { get; set; } protected override DataTemplate SelectTemplateCore(object item) {