0

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 across all three controls, but still have different Event and ItemsSource?

Mike
  • 13
  • 2

2 Answers2

0

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.

Community
  • 1
  • 1
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
  • That should work :) However, I still think I'm going to extract everything out into it's own user control, and just inherit from the other custom control. I'll try both. Thanks! – Mike Sep 01 '11 at 17:35
0

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.

tsells
  • 2,751
  • 1
  • 18
  • 20
  • Normally I would too. Unfortunatly, this isn't code I can change due to it being baked into the application in HUNDRED+ spots. – Mike Sep 01 '11 at 17:31