datatemplate

Stop TabControl from recreating its children

梦想的初衷 提交于 2019-12-17 02:59:45
问题 I have an IList of viewmodels which are bound to a TabControl . This IList will not change over the lifetime of the TabControl . <TabControl ItemsSource="{Binding Tabs}" SelectedIndex="0" > <TabControl.ItemContainerStyle> <Style TargetType="TabItem"> <Setter Property="Content" Value="{Binding}" /> </Style> </TabControl.ItemContainerStyle> </TabControl> Each viewmodel has a DataTemplate which is specified in a ResourceDictionary . <DataTemplate TargetType={x:Type vm:MyViewModel}> <v:MyView/> <

How can I bind to a DataTemplate in code?

余生长醉 提交于 2019-12-14 04:12:14
问题 I have a data template defined in XAML and accessible by calling App.Current.Resources["foo"] . I can't define the Data Bindings on the template in XAML because the source for the bindings is not accessible from the visual tree ( the sources are DataGridColumn type objects ), so I have to define the bindings in code behind. How do I attach bindings to a DataTemplate so that when .LoadContent( ) is called, the result will have respect the specified data bindings? In compliance with the Minimal

ItemsControl DataTemplate Items showing side by side

百般思念 提交于 2019-12-14 02:11:31
问题 I've been researching this for quite long time now, can't find the answer. How can I display each item in my itemscontrol side by side? The following code displays each item's content side by side (label and textbox), but the next item is shown underneath. Let's say I have 3 items in my ItemsControl. The current behaviour is: Label Textbox Label Textbox Label Textbox What I want is: Label Textbox Label Textbox Label Textbox (side by side) The current code uses a stack panel whick sets the

How expensive is data templating? [closed]

匆匆过客 提交于 2019-12-14 02:02:27
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I have performance problems and I am trying to dig the reasons. So far I am not sure what is the problem and my next assumption it's data templating. Question: how expensive is using data-templating ? Lets see how expensive is single data template. Below is mcve. xaml:

WPF Binding to DependencyProperty of UserControl in DataTemplate is not working

时光总嘲笑我的痴心妄想 提交于 2019-12-13 18:24:16
问题 i have a custom userControl with DPs and have the problem that the binding to these properties only works if i use the controls outside of datatemplates. Outside of Datatemplates works the usercontrol great. XAML to Test the UserControl in a DataTemplate <GroupBox Header="DataTemplate" Padding="5"> <ItemsControl ItemsSource="{Binding Dummies}"> <ItemsControl.ItemTemplate> <DataTemplate DataType="local:Dummy"> <StackPanel Orientation="Horizontal" Margin="2"> <common:QuarterPicker

DataTemplates to display a collection of Points as Ellipses in WPF

半世苍凉 提交于 2019-12-13 16:54:18
问题 In my application, the user is supposed to click over an image, and as he clicks some dots appear. Also he can remove them by right clicking, etc. So I have a test project composed of a single Window (xaml + codebehind) with a canvas, and I am handling some of its events, as MouseMove and MouseLeftButtonDown which are going to add points to an ObservableCollection<Point> in code behind. I already have this, what I don't know is how I'm supposed to implement data-templating and databinding so

Why does DataTemplate.LoadContent() not respect template-defined triggers?

帅比萌擦擦* 提交于 2019-12-13 15:09:30
问题 TL-DR version: We're trying to figure out what the difference is between the automatic application of a DataTemplate where triggers are in effect vs. manually calling DataTemplate.LoadContent() where triggers are not in effect. Now the details... But first, let me start by saying this question is to help us understand the framework and what it's doing internally, and as such, the associated code is strictly to demonstrate the question itself and does not represent our actual code in any way.

WPF How to Create a DataTemplate Which has Canvas As Content By Code?

强颜欢笑 提交于 2019-12-13 10:25:01
问题 I have the data template defined by XAML as below: <DataTemplate x:Key="PointPushPinItemTemplate"> <mapControl:MapItem mapControl:MapPanel.Location="{Binding}" > <Canvas> <Path StrokeThickness="2" Fill="Aqua"> <Path.Data> <EllipseGeometry RadiusX="10" RadiusY="10"/> </Path.Data> </Path> </Canvas> </mapControl:MapItem> </DataTemplate> I use below code to create it, but failed: private DataTemplate PushPinPointDataTemplate() { var pointItemFactory = new FrameworkElementFactory(typeof(MapItem));

WPF FlowDocument :: How Can I Define Custom Templates for the Child Paragraph, Run, etc

我与影子孤独终老i 提交于 2019-12-13 06:52:37
问题 I'm fairly new to WPF, so please bear with me. I am trying to customize the presentation of the various elements of a FlowDocument in a RichTextBox (RTB). WPF controls are lookless, so as I understand it I should be able to define the look for every child in the Document . Would I define the template for this in the RTB? Separate templates for each item ( Paragraph , Section , Run , etc) as resources? Let's say, for sake of argument, that I want a red border around every Section , the word

DisplayStateBehavior not initially applying state transition in listbox item template

限于喜欢 提交于 2019-12-13 04:43:12
问题 I have a listbox item template that contains visual states. I have DisplayStateBehaviors that set the states to either the on/off states. My implementation only 1/2 works. On initial display, the base state is active, regardless of the value in the DataContext. When the data in the DataContext changes, the proper state is activated. How do I get the proper state displayed on initial display of the listbox. For security reasons I can not copy/paste XAML or View-Model code. Edit : While I can't