datatemplate

ContentTemplateSelector is only called one time showing always the same datatemplate

拈花ヽ惹草 提交于 2019-11-30 13:58:49
I have made a sample demo VS 2010 RC sample project, because in my production project I have the same error using MVVM. In my sample demo project I use only Code-behind without 3rd party dependencies so you can download the demo project here and run it for yourself: http://www.sendspace.com/file/mwx7wv Now to the problem: When I click the girls/boys button it should switch the datatemplate, not? What do I wrong? OK I offer here a code snippet too: Code-Behind MainWindow.cs : namespace ContentTemplateSelectorDemo { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public

How to build a generic/re-usable modal dialog for WPF following MVVM

僤鯓⒐⒋嵵緔 提交于 2019-11-30 13:24:39
问题 I would like to build a generic/re-usable modal dialog that I can use in our WPF (MVVM) - WCF LOB application. I have a Views and associated ViewModels that I would like to display using dialogs. Bindings between Views and ViewModels are done using Type-targeted DataTemplates. Here are some requirements that I have been able to draft: I prefer this to be based on a Window instead of using Adorners and controls that act like a modal dialog. It should get its minimum size from the content. It

Should I be using UserControls for my Views instead of DataTemplates?

不羁岁月 提交于 2019-11-30 11:48:01
I was reading this post and the author makes the suggestion that using DataTemplates to define a ViewModel is a lunatic's way to do it (#7). I do that all the time, is it really that bad? <DataTemplate DataType="{x:Type local:MyViewModel}"> <Grid> ... </Grid> </DataTemplate> Most of my Views are simply a ResourceDictionary that defines a DataTemplate or two. To me, it makes much better sense to do this than creating a UserControl for every ViewModel. Why would I want the extra layer in WPF's visual tree when it's not needed? And why would I want to take care of mapping ViewModels to Views when

How to use template binding inside data template in custom control (Silverlight)

爷,独闯天下 提交于 2019-11-30 11:38:56
I am trying to create control which will take ItemsSource and InnerTemplate and will show all the items wrapped in CheckBox es. The control has 2 dependency properties: public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(CheckBoxWrapperList), null); public static readonly DependencyProperty InnerTemplateProperty = DependencyProperty.Register("InnerTemplate", typeof(DataTemplate), typeof(CheckBoxWrapperList), null); and here is the template: <ControlTemplate TargetType="local:CheckBoxWrapperList"> <Grid> <Grid

WPF - Display single entity with a data template

南笙酒味 提交于 2019-11-30 11:17:05
I Have a data template that i use in items control, i wanna know if its possible some how to use it(the template) on single item display without the items control? if not whats the best way to do it...? toxvaerd You can probably do something like this **<DataTemplate x:Key="MyTemplate" DataType="{x:Type MyType}">** ... **</DataTemplate>** ... <ContentControl ContentTemplate="{StaticResource MyTemplate}" /> <!-- Single instance use --> <ItemsControl ItemTemplate="{StaticResource MyTemplate}" /> <!-- Multiple instance use --> 来源: https://stackoverflow.com/questions/755167/wpf-display-single

Binding to viewmodel from inside a datatemplate

自古美人都是妖i 提交于 2019-11-30 10:57:02
I have multiple videos displayed they are bound with a videocollection in Mainviewmodel. Everything works fine untill I try to bind the enter command to Mainviewmodel. I Don't know the syntax for this. As it stands the binding is set to Video and not Mainviewmodel. Errormessage: 'StartVideoCommand' property not found on 'object' ''Video' Xaml: <Window.Resources> <local:MainViewModel x:Key="MainViewModel"/> </Window.Resources> <Grid DataContext="{StaticResource MainViewModel}"> <ListBox ItemsSource="{Binding Videos}"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.InputBindings> !!!

How to declare combobox itemTemplate that has Itemsource as Enum Values in WPF?

最后都变了- 提交于 2019-11-30 09:32:27
I have a enum let's say enum MyEnum { FirstImage, SecondImage, ThirdImage, FourthImage }; I have binded this Enum to my combobox in XAML. While defining an combobox I have defined an ItemTemplate of combox to take Two UI element: TextBlock that show the enum value (Description) Image I have done this much in XAML. I am wondering where I can specify the Image corrosponding to each item of Enum value in a combobox? Is that possible through data trigger ? I really appreciate if anyone have the XAML for this scenario. Many Thanks in advance You can use a DataTrigger, but would be more maintainable

Windows Phone 7 - Setting style for specific control within selected ListBoxItem

雨燕双飞 提交于 2019-11-30 09:09:56
问题 let's say i have something like this: <Grid> <ListBox x:Name="list" ItemsSource="{Binding SomeCollection, Mode=TwoWay}" SelectedItem="{Binding SomeItem, Mode=TwoWay}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock x:Name="first" Text="{Binding SomeProperty}" /> <TextBlock x:Name="second" Text="{Binding OtherProperty}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> Now, how do i alter some style property (f.ex. FontSize) of only the TextBlock called "second" when a

Selecting a data template based on type

眉间皱痕 提交于 2019-11-30 08:59:35
问题 I've declared the following types: public interface ITest { } public class ClassOne : ITest { } public class ClassTwo : ITest { } In my viewmodel I'm declaring and initializing the following collection: public class ViewModel { public ObservableCollection<ITest> Coll { get; set; } = new ObservableCollection<ITest> { new ClassOne(), new ClassTwo() }; } In my view I'm declaring the following ItemsControl <ItemsControl ItemsSource="{Binding Coll}"> <ItemsControl.Resources> <DataTemplate DataType

Binding to ItemsSource of TabControl in WPF

佐手、 提交于 2019-11-30 07:42:18
问题 I am trying to create a User Control that represents what I am calling a workspace (a reference from a blog by Josh Smith). The workspaces will be displayed in a tab control. I am aiming to use a tabbed interface to manage various documents that I have open much like in a browser of an excal work book. Each time a user opens a new workspace, that workspace should be displayed in the tab control. Each Workspace takes the form of a user control, and each workspace has its own view model. I