datatemplateselector

WPF: Find Resources from UserControl within DataTemplateSelector class

谁说胖子不能爱 提交于 2019-12-09 06:30:18
问题 I know there is this thread: How to find a resource in a UserControl from a DataTemplateSelector class in WPF? asking the same. BUT... I am not satisfied with the answer! THERE MUST be a way to grab the Resources of the UserControl containing the ContentControl/Presenter declaring this: ContentTemplateSelector="{StaticResource MySelector}" Each derived DataTemplateSelector class a parameter in its SelectedTemplate Method => container which is typeof DependencyObject. Well container is in my

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="

Dynamically Load Content with WPF

白昼怎懂夜的黑 提交于 2019-12-08 01:55:02
问题 Ok I have a container that I have created two data templates for. Basically one template will show 5 textboxes with and objects data bound to them and the other template will show a button to add that particular object. I subclassed DataTemplateSelector and it works, but when I navigate through my records the Selector never gets called again. So how would I for the container to reselect it's template. The container is a StackPanel and I have already tried UpdateVisuals, InvalidateVisuals,

WPF DataGrid with different UserControl in each Cell

江枫思渺然 提交于 2019-12-06 14:21:39
问题 I hava a data model which looks like this: public class Model { public string DisplayAs {get;set;} // TextBox, CheckBox, ComboBox public string Value {get;set;} public string DisplayName {get;set;} // Row1, Row2, ... } Now I want to display these models in a Datagrid which shall look like this: How could I achieve this? Please provide some example code. I tried the whole day with different kind of DataTemplateSelectors but I just can't get it working 回答1: Your selector selects a template for

Dynamically Load Content with WPF

泪湿孤枕 提交于 2019-12-06 06:55:20
Ok I have a container that I have created two data templates for. Basically one template will show 5 textboxes with and objects data bound to them and the other template will show a button to add that particular object. I subclassed DataTemplateSelector and it works, but when I navigate through my records the Selector never gets called again. So how would I for the container to reselect it's template. The container is a StackPanel and I have already tried UpdateVisuals, InvalidateVisuals, InvalidateArrange, and ApplyTemplate. XAML Code <DataTemplate x:Key="advisorTemplate"> <StackPanel

DataTemplate for a DataType - how to override this DataTemplate in a particular ListBox?

雨燕双飞 提交于 2019-12-05 21:36:29
I have created several DataTemplates for some of the DataTypes in my pet project. These data templates are really cool as they work like magic, magically transforming the look of the instances of the data types whenever and wherever they show up in the UI. Now I want to be able to change the DataTemplate for these DataTypes in one particular ListBox. Does this mean I have to stop relying on WPF automatically applying the data template to the data types and assign a x:Key to the DataTemplates and then apply the Template/ItemTemplate in the UI using that key? A ListBox contains items of various

Switching ListBox ItemTemplate based on both item type and view option

不打扰是莪最后的温柔 提交于 2019-12-05 05:56:08
问题 I'm currently implementing a listbox in WPF that will have 2 alternative layouts for its items: So far, I've done this using a DataTrigger to switch the ItemTemplate for the ListBox and it's working well: <ListBox ItemsSource="{Binding Runs}" SelectedItem="{Binding SelectedRun}"> <ListBox.Style> <Style TargetType="ListBox"> <Setter Property="ItemTemplate" Value="{StaticResource tileTemplate}"/> <Style.Triggers> <DataTrigger Binding="{Binding ShowRunsAsIcons}" Value="True"> <Setter Property=

LongListSelector and DataTemplateSelector

扶醉桌前 提交于 2019-12-04 20:06:27
问题 I'm using the LongListSelector to realize List or Grid display for my items. For this, I created a DataTemplateSelector and I change the LayoutMode property at runtime. This is working but there seems to be an issue with the DataTemplateSelector. If I initially launch the page, the DataTemplateSelector is called three times for my three items. When I navigate to another page (settings page to change the LayoutMode) and then back, the DataTemplateSelector is just called two items but there are

WPF: Find Resources from UserControl within DataTemplateSelector class

戏子无情 提交于 2019-12-03 08:06:27
I know there is this thread: How to find a resource in a UserControl from a DataTemplateSelector class in WPF? asking the same. BUT... I am not satisfied with the answer! THERE MUST be a way to grab the Resources of the UserControl containing the ContentControl/Presenter declaring this: ContentTemplateSelector="{StaticResource MySelector}" Each derived DataTemplateSelector class a parameter in its SelectedTemplate Method => container which is typeof DependencyObject. Well container is in my case the contentcontrol. Would it not be possible to climb up the visual tree starting at

How to use DataTemplateSelector with ContentControl to display different controls based on the view-model?

你离开我真会死。 提交于 2019-12-01 13:46:36
I want to create a simple window that would display different controls ( SpinEdit or TextEdit ) based on the view-model that is selected. I have the code and logic behind it done already, what is left is displaying the control ( SpinEdit or TextEdit ) itself. XAML: <dx:DXWindow.Resources> <DataTemplate x:Key="DataTemplate_Value"> <dxe:SpinEdit Height="23" MinWidth="200" Width="Auto" Text="{Binding Path=Value, Mode=TwoWay}" Mask="{Binding Mask, Mode=OneWay}" MaxLength="{Binding Path=InputLength}" /> </DataTemplate> <DataTemplate x:Key="DataTemplate_Text"> <dxe:TextEdit Height="23" MinWidth="200