开发者

WPF Binding in a Style Help?

开发者 https://www.devze.com 2023-04-01 02:51 出处:网络
I have a style to a custom control that inherits from combobox that I can\'t modify.Inside this style, there\'s a DataGrid control that takes in a ItemsSource, the DataGrid also has an x:Name that nee

I have a style to a custom control that inherits from combobox that I can't modify. Inside this style, there's a DataGrid control that takes in a ItemsSource, the DataGrid also has an x:Name that needs to get referenced in code somewhere, probably due to the event.

So basically

    <Style x:Key="ComboBoxStyle" TargetType="ComboBox">
        <Setter Property="Template">
            <Setter.Value>

               ... A whole bunch of other stuff.

               <xcdg:DataGridControl 
                 x:Name="CustomItemOneGrid"
                 ItemsSource="{Binding Source={StaticResource CustomItemOne_DataSource}}"
                 SelectionChanged="CustomItemOneGrid_SelectionChanged">

My problem here is that CustomItemOne_DataSource, well there's 3 times I'll use this control and well 3 datasources. Also, the selection changed event I need to subscribe to also. Is there a way to keep this in a style I can use开发者_Python百科 across all three controls, but still have different Event and ItemsSource?


Define attached properties for the items that can change that are not defined by the ComboBox class (eg. GridItemsSource). Then bind to those attached properties in your template. Much like I discuss here.


Normally I let me DataContext flow down from the Control that is implementing the style / data template and then bind to a property on that control. I wouldn't use StatisResources for your bindings.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号