Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Simple request - converting xaml to a style

$
0
0

Hi all,

I have a comboBox where I have defined a DataTemplate so I can have multiple columns.  The combo box looks like this:

<ComboBox Name="cboCit_type"
  IsSynchronizedWithCurrentItem="True"    
  mvvm:View.FlowsWithPrevious="True"
  ItemsSource="{Binding Path=cuCodeInfo.CitTypes}"
  SelectedValuePath="code" 
  Text="{Binding cit_type}"
  TextSearch.TextPath="code"
  IsEditable="true"
  IsReadOnly="false"
  SelectedValue="{Binding cit_type}"><ComboBox.ItemTemplate><DataTemplate><StackPanel Orientation="Horizontal" ><Border BorderThickness="0,0,1,0" BorderBrush="Black"><TextBlock Text="{Binding Path=code}" mvvm:View.WidthEx="2" ></TextBlock></Border><TextBlock Text="{Binding Path=description}" mvvm:View.WidthEx="15" Margin="1" ></TextBlock></StackPanel></DataTemplate></ComboBox.ItemTemplate></ComboBox>

I want to convert it so that most of it is using a sytle.  This is because I will be using many of the same values again and again. So here is what I have that works so far:

<Style BasedOn="{StaticResource {x:Type ComboBox}}"
					 TargetType="ComboBox"
					 x:Key="cboCodeTypeStyle"><Setter Property="IsSynchronizedWithCurrentItem"
							Value="True" /><Setter Property="SelectedValuePath"
							Value="code" /><Setter Property="IsEditable"
							Value="true" /><Setter Property="IsReadOnly"
							Value="false" /><Setter Property="mvvm:View.FlowsWithPrevious"
							Value="True" /><Setter Property="TextSearch.TextPath"
							Value="code" /></Style>

So far, so good.

But now I am trying to figure out how to move the DataTemplate to the style.  Everything I have tried so far fails.  I am sure this is a very simple conversion, but in the searching I have done, I can't find the steps to manage it.

Any help is appreciated!

Thanks


me (and yes, I DO mark correct answers)



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>