views:

27

answers:

1

I've got the following user-control:

Resources:

    <DataTemplate x:Key="FilterComboDataTemplate">
        <Label Content="{Binding Item2}" />
    </DataTemplate>

    <Style x:Key="FilterSelectorStyle" TargetType="ComboBox">
        <Setter Property="ItemsSource" Value="{Binding Filters}" />
        <Setter Property="SelectedItem" Value="{Binding SelectedFilter}" />
        <Setter Property="ItemTemplate" Value="{StaticResource FilterComboDataTemplate}" />
    </Style>

Control Body:

<DockPanel>
    <Label DockPanel.Dock="Top">
        Select your filter/value to apply:
    </Label>
    <ComboBox Style="{StaticResource FilterSelectorStyle}" />
    <StackPanel>
        <!-- TODO: Fix Combobox First -->
    </StackPanel>
</DockPanel>

It's inside a <Window> and opened using .ShowDialog(), this is what happens to the items when I click on the button:

Undesirable Results

I'm at a complete loss as to why this is happening, I've checked the visual tree, everything's where it should be. I'm baffled. Anyone out there experienced strange behavior like this? Why are my items at 0,0 on my desktop instead of attached to my combobox?

+1  A: 

I quickly coded this. Didn't have any problem.

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:WpfApplication5="clr-namespace:WpfApplication5" x:Class="WpfApplication5.MainWindow"
        x:Name="MyWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>          
        <DataTemplate x:Key="FilterComboDataTemplate">
            <Label Content="{Binding Item2}" />
        </DataTemplate>
    </Window.Resources> 
    <DockPanel>

        <Label DockPanel.Dock="Top">
            Select your filter/value to apply:
        </Label>

        <ComboBox Height="32" ItemsSource="{Binding Filters, ElementName=MyWindow}" ItemTemplate="{DynamicResource FilterComboDataTemplate}"/>

        <StackPanel>
            <!-- TODO: Fix Combobox First -->
        </StackPanel>

    </DockPanel>
</Window>

Also, I've never seen any one putting ItemSource and SelectedItem in a style. I don't think that's a good WPF practice. I will rather bind to a ICollectionView which allows grouping, filtering, managing cursor etc

chown
The reason it's in a style is that a couple comboboxes will require the exact same settings, it's to reduce XAML Duplication.
Aren
Danm, can't edit my previous comment. Also: It is bound to an `ICollectionView`, **Filters** on the datacontext is of type `ICollectionView`. I also just moved all the bindings out onto the ComboBox itself and I'm still getting this problem.
Aren