locked
Custom style of a ListBox item RRS feed

  • Question

  • I am a programmer, not a graphic artist, so I am as comfortable with the XAML as I am with the GUI.  Below is the DataTemplate I have created for the ListBox's ItemTemplate.  The objective is to change the selected state of the selected item such that the first TextBlock in the DataTemplate has a different color background, the button has different text and is in a disabled state. 

    I am thinking I can do this by defining defining a style of the ListBoxItem, then for the selected state define a style for the text and button.  I am sure folks could explain how to do this in code, but I would like to understand how to this in Blend 3, too.

    Q: The question is how do I do this in Blend 3?  Are there any tutorials out there to do this type of thing?

    <DataTemplate x:Key="PriceListItemTemplate">
      <Grid Margin="0,4,0,0" d:DesignWidth="200">
        <Border BorderThickness="0,1,0,0">
          <Border.BorderBrush>
            <SolidColorBrush Color="{StaticResource borderColor}"/>
          </Border.BorderBrush>
          <Grid>
            <StackPanel Margin="8" d:LayoutOverrides="Width">
              <TextBlock TextWrapping="Wrap"
                Text="This 80's char sting has stuff in it for the heck of it, so lets get it there!!!"
                />
    
              <Grid Margin="7">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="0.5*"/>
                  <ColumnDefinition Width="0.5*"/>
                </Grid.ColumnDefinitions>
    
                <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                  <TextBlock Text="8x10" Grid.ColumnSpan="2" VerticalAlignment="Center" />
                  <TextBlock Text="14.95" Grid.ColumnSpan="2" VerticalAlignment="Center" />
                </StackPanel>
    
                <Button Padding="8,4" Grid.Column="1" Height="23"
                  Content="{Binding StringLibrary.ProductCreateItem, Source={StaticResource LocalizedStrings}}"
                  Visibility="{Binding IsAddButtonEnabled, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}"
                  />
              </Grid>
            </StackPanel>
    
          </Grid>
        </Border>
      </Grid>
    </DataTemplate>
    

    Tuesday, May 24, 2011 1:27 AM

All replies