Selection behavior on XamTilesControl with Attached properties

XamTilesControl is a derived ItemsControl and does not support selection. If you want to have the notion of selected item(s) you can achieve this by using attached properties. Creating attached properties can extend the functionality of the XamTilesControl and the Tiles to create a simple selection behavior for the XamTilesControl.

Behavior class: (actual code is omitted because of length)

SelectionAdvisor : DependencyObject

Attached Properties:

bool IsSelected

bool AllowMultipleSelection

Tile  SelectedTile

How it works:

AllowMultipleSelection property is set on the XamTilesControl to allow or forbid selecting multiple tiles.

SelectedTile property is also set on the XamTilesControl and returns the last selected tile.

IsSelected is being set on the Tile to indicate whether a Tile is selected or not.

Create a style to visually represent the state of the Tile:

 <Style TargetType="{x:Type igTiles:Tile}"> 
      <Style.Triggers> 
            <DataTrigger Binding="{Binding Path=(selection:SelectionAdvisor.IsSelected), RelativeSource={RelativeSource Self}}" Value="True"> 
                    <Setter Property="Background" Value="{DynamicResource {x:Static igTiles:TileBrushKeys.TileCaptionBtnHottrackBackgroundFillKey}}" /> 
            </DataTrigger> 
      </Style.Triggers> 
 </Style>
 

Full sample :XamTilesControl_SelectedItem (Modified).zip


Add a Comment

Be the first one to add a comment. Please Login or Register to add comment.