datatemplate

UWP DataTemplates for multiple item types in ListView

别来无恙 提交于 2019-12-03 12:52:26
How would I go about implementing this? Let's say this is my model: public interface IAnimal { string Name { get; } } public class Fish : IAnimal { public string Name { get; set; } public int ScalesCount { get; set; } } public class Dog : IAnimal { public string Name { get; set; } public string CollarManufacturerName { get; set; } } public class ViewModel { public ObservableCollection<IAnimal> Animals { get; set; } public ViewModel() { this.Animals = new ObservableCollection<IAnimal>(); this.Animals.Add(new Fish { Name = "Carl", ScalesCount = 9000 }); this.Animals.Add(new Dog { Name = "Fifi",

WPF - Databind to a StackPanel using DataTemplates

不羁岁月 提交于 2019-12-03 11:57:10
I've modified my question since it has changed focus when trying things out. I narrowed the problem down to the following... I try to bind the selected Item of a TreeView to a StackPanel (or some other container that can hold User Controls). This container will then display a UserControl, depending on the type of the selected item. Here is the xaml of the StackPanel (both treeview and stackpanel are in the same window ==> different grid column) <StackPanel Grid.Column="2" MinWidth="500" DataContext="{Binding ElementName=myTree, Path=SelectedItem, Mode=OneWay}"> <StackPanel.Resources>

WPF - Very basic ListBox.ItemTemplate Question

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 11:37:59
问题 Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I'm learning about DataTemplating and am trying to apply a very VERY simple ItemTemplate to a ListBox. However, when I run my app, the template is completely ignored and I just get the standard-looking listbox, whereas in fact I'd expect to see a list of checkboxes with 'Test' along side. I've tried this several times and always the same result. I've checked several resource on Google and all have the same kind of

WPF DataTemplate property set at Content

青春壹個敷衍的年華 提交于 2019-12-03 08:42:11
New to WPF and have Tabs and in each tab the content is presented in a curved corner panel/window/whateveryouwannacallit. I wasn't sure how to do this ( Style, ControlTemplate ) but decided to go the DataTemplate way. So now I have this DataTemplate: <DataTemplate x:Key="TabContentPresenter" > <Border Margin="10" BorderBrush="{StaticResource DarkColorBrush}" CornerRadius="8" BorderThickness="2" Grid.Row="0" Padding="5" Background="{TemplateBinding Background}"> <ContentPresenter Content="{Binding}" /> </Border> </DataTemplate> As you can see with the the background property I wan't to set the

WPF Memory Usage

早过忘川 提交于 2019-12-03 06:39:53
Application: WPF Application consisting of a textbox on top and a listbox below Users type a string in the TextBox to find employees, and search results are displayed in the ListBox ListBox uses DataTemplates to display elements (shows employee name, department, phone and a thumbnail picture.) Implementation: At application startup I query the database and retrieve all employees and related information to be shown in the ListBox. This is kept in memory the entire time. After application startup, all the searchable data is in memory and searches are virtually instantaneous. All searches are

Making a DataTemplate blendable

房东的猫 提交于 2019-12-03 03:53:04
问题 How can I make a Datatemplate for a ViewModel blendable (designable in expression blend). When I go to resources and try to edit the DataTemplate directly all I see on the Drawingborad is a blank rectangle. This is because the DataTemplate is not bound to anything. Of course I can create a UserControl and create some designtime data in code there to see the template but I now would have to switch back and forth between the resource (to edit) and the usercontrol (to see the result of my edit).

Dynamically added DataTemplate - StaticResource for Converter can't be found

╄→尐↘猪︶ㄣ 提交于 2019-12-03 03:38:08
I'm using the following code to dynamically add columns to my GridView: public void AddGridViewColumns() { GridView view = (GridView)_myListView.View; GridViewColumn column = BuildGridViewColumn(1); view.Columns.Add(column); } public virtual GridViewColumn BuildGridViewColumn(int blockIndex) { string templateXaml = string.Format( @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:local=""clr-namespace:Pse.MyTest;assembly=MyTest""> <DataTemplate.Resources> <local:BlockToBrushConverter x:Key=""

WPF - Very basic ListBox.ItemTemplate Question

。_饼干妹妹 提交于 2019-12-03 02:05:48
Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I'm learning about DataTemplating and am trying to apply a very VERY simple ItemTemplate to a ListBox. However, when I run my app, the template is completely ignored and I just get the standard-looking listbox, whereas in fact I'd expect to see a list of checkboxes with 'Test' along side. I've tried this several times and always the same result. I've checked several resource on Google and all have the same kind of syntax for defining and ItemTemplate on a ListBox, so I really cannot see where I'm going wrong. Code...

Making a DataTemplate blendable

六眼飞鱼酱① 提交于 2019-12-02 18:11:27
How can I make a Datatemplate for a ViewModel blendable (designable in expression blend). When I go to resources and try to edit the DataTemplate directly all I see on the Drawingborad is a blank rectangle. This is because the DataTemplate is not bound to anything. Of course I can create a UserControl and create some designtime data in code there to see the template but I now would have to switch back and forth between the resource (to edit) and the usercontrol (to see the result of my edit). Isn't there a more direct way to edit and see my DataTemplate? Anderson Imes It's a bit of a stretch

WPF MVVM Binding dynamic control in code behind and pass in View

不想你离开。 提交于 2019-12-02 13:15:05
I am working on WPF application using MVVM. I have two page. I have multiple UserControls in a page 1, on selection of UserControls from page 1, I want to show that selected userControl in 2nd page. Below are my code. ViewModel Code public RelayCommand<string> OnClickSelectWidgetCommand => new RelayCommand<string>((setUserControlName) => { using (new CursorWait()) { var MyContentControl = setUserControlName; MessageBox.Show(MyContentControl); //How to render UserControl to View? } }, true); Here in above code I get the UserControl name in setUserControlName variable. Now how to bind that