datatemplate

ComboBoxItem continues to throw binding error despite style

◇◆丶佛笑我妖孽 提交于 2019-12-07 11:14:51
问题 Good day, I have a combobox that I am populating via a CollectionViewSource. The items are build though a datatemplate for the incoming item type (in this case a ProjectViewModel). This is in WPF in .NET 4.0. In my window.resources, I have specified the following: <Style TargetType="{x:Type ComboBoxItem}"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Center"/> </Style> Despite this style, I am still getting the following

Validate PasswordBox in WPF

岁酱吖の 提交于 2019-12-07 09:22:47
问题 Is there a way to show error message in AdornedElementPlaceholder while verifiying PasswordBox. I have something like this: <ControlTemplate x:Key="DefaultErrorTemplate"> <StackPanel Orientation="Horizontal"> <AdornedElementPlaceholder x:Name="placeholder" /> <Border Background="Red" ToolTip="{Binding ElementName=placeholder, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" ToolTipService.InitialShowDelay="0" VerticalAlignment="Top" Margin="3" Width="20" Height="20" CornerRadius="10"

XBF Error with DataTemplate in Application.Resources

好久不见. 提交于 2019-12-07 08:49:03
问题 Universal Windows Platform app with Visual Studio 2015 (RTM) I have a DataTemplate that is used in multiple pages of my app, so I'd prefer to write it once and access it from anywhere I need to. In order to make it accessible by any page, I write it in my App.xaml 's <Application.Resources> : <Application x:Class="MyApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:MyApp" xmlns:viewmodels="using

Why should we use DataTemplate.DataType

佐手、 提交于 2019-12-07 08:06:07
问题 When I am creating a Resource we are specifying the DataType inside it: <Window.Resources> <DataTemplate x:Key="StudentView" DataType="this:StudentData"> <TextBox Text="{Binding Path=StudentFirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" /> <TextBox Text="{Binding Path=StudentGradePointAverage}" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" /> </DataTemplate> <Window.Resources> And while binding : <ItemsControl

How can I retrieve the DataTemplate (and specific objects) of an item in an ItemsControl?

为君一笑 提交于 2019-12-07 07:34:02
问题 I have seen solutions to a very similar issue, yet it doesn't translate to mine. (Namely, this article: http://blogs.msdn.com/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx) My ItemsControl is bound to an observable collection, which can have items dynamically added to it. When I add an item to the observable collection, the templated item renders properly in my itemscontrol, but I can't figure out how to access it. My my observable

How can data templates in generic.xaml get applied automatically?

两盒软妹~` 提交于 2019-12-07 04:28:00
问题 I have a custom control that has a ContentPresenter that will have an arbitrary object set as it content. This object does not have any constraint on its type, so I want this control to display its content based on any data templates defined by application or by data templates defined in Generic.xaml. If in a application I define some data template(without a key because I want it to be applied automatically to objects of that type) and I use the custom control bound to an object of that type,

When to use TemplateBinding and TemplatedParent in WPF

僤鯓⒐⒋嵵緔 提交于 2019-12-07 03:41:55
问题 I have a confusion over TemplateBinding and TemplatedParent. I have gone through this link also WPF TemplateBinding vs RelativeSource TemplatedParent But my doubt is when to use TemplateBinding and TemplatedParent? Thanks in advance. 回答1: {TemplateBinding X} is simply a shortcut way of writing the {Binding X, RelativeSource={RelativeSource TemplatedParent}} . They evaluate to the same thing, although TemplateBinding is evaluated at compile-time while RelativeSource TemplatedParent is

Making a grid in a ListView ItemTemplate fill

十年热恋 提交于 2019-12-06 23:58:01
问题 I have a ListView which has a data template based on a grid. The xaml is as follows: <ListView ItemsSource="{Binding SomeItemSource}" HorizontalAlignment="Stretch" Height="281"> <ListView.ItemTemplate> <DataTemplate> <Grid HorizontalAlignment="Stretch" Margin="3" Width="Auto"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="70"></ColumnDefinition> <ColumnDefinition Width="*"><

How to change the menu content by using DataTrigger in XAML?

点点圈 提交于 2019-12-06 20:06:18
I have two kinds of menu items according to the login. So, by using the property in the ViewModel Class bool IsAdmin {get; set;} I have to change the menu item content.I am not familiar with data template. I want to define all the menu items in the xaml itself (might be using the data templates). How we can bind the differnt menu items by using the data trigger. Can anyone can give a smaller example for this. using only this property and no c# codes. Noam M Use ContentControl and Styles for max flexability in changing the view betwin Admin or not Admin views <UserControl.Resources> <!--*******

Why using UserControl inside DataTemplate is slower than direct xaml?

妖精的绣舞 提交于 2019-12-06 14:05:25
I have code as this one: <ListBox ItemsSource="{Binding Items}"> <ListBox.ItemTemplate> <DataTemplate DataType="{x:Type local:MyViewModel}"> <!-- xaml is typed here directly --> <Border> ... </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox> And xaml inside the DataTemplate is big (more than 200 lines). I want to move xaml which is inside the DataTemplate into a separate UserControl to make it easier to edit and maintain. I do next: <ListBox ItemsSource="{Binding Items}"> <ListBox.ItemTemplate> <DataTemplate DataType="{x:Type local:MyViewModel}"> <!-- xaml is moved to separate