views:

116

answers:

1

In short: I want to define what XML ButtonSettings element to use for a XAML-Button, and to use the childs of the selected ButtonSettings-element in a style applied to that Button.

Is this possible?

A sample of the XML:

<Buttons>
  <ButtonSettings ID="Bye">
    <Text lang="NL">Doei!</Text>
    <Text lang="DE">Tsusch!</Text>
    <Text lang="FR">Bonjour</Text>
    <Text lang="EN">CU</Text>
    <Image>D:\bye.PNG</Image>
  </ButtonSettings>
</Buttons>

For each button, I want to select which ButtonSettings to use, specifying it's ID. Then, I want to pass that ButtonSettings-element to the style as a binding or datacontext. The childs of the selected element (e.g Text and Image) will then be used in the style.

Selecting and defining the content of a button works perfectly, as long as I define it directly at the button and not in a style. This is the XAML I have for a single Button:

<Button
      x:Name="ByeButton" 
            DataContext="{StaticResource dataProvider}">
            <Button.Content>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0">
                        <TextBlock.Text>
                            <Binding XPath="//ButtonSettings[@ID='Bye']/Text[@lang='FR']" />
                        </TextBlock.Text>                        
                    </TextBlock>
                    <Image Grid.Row="1" Width="20" Height="20">
                        <Image.Source>
                            <Binding XPath="//ButtonSettings[@ID='Bye']/Image" />
                        </Image.Source>
                    </Image>
                </Grid>
            </Button.Content>
        </Button>

I want to be able to define //ButtonSettings[@ID='id'] for each button and let a style handle the rest of laying out the buttons and putting content and text in. Can this be done?

+1  A: 

I think you are looking for an ItemsControl and place your button inside of a DataTemplate that targets your DataType.

Steven
Well, the point is that I want to specify, for each button, which instance of ButtonSettings to use, by passing the Button the ID of the Buttonsettings-instance. With an ItemsContol, like a lostbox, the listbox specifies which each items gets. That qway, I have less control over my UI.
Loy