Estou criando um menu dinâmico usando Tiles
(MahApps). Tenho dois tipos de Tiles
que posso utilizar: LargeTileStyle e SmallTileStyle. Para isso, tenho uma função que me permite passar o nome do Style
via parâmetro e setar a propriedade Style
, quando o Tile
for criado.
Criação dos Tiles
:
this.Tile.Add(
new TileItem()
{
Icon = new PackIconFontAwesome()
{
Kind = PackIconFontAwesomeKind.Angellist
},
Text = "Usuários",
Style = "LargeTileStyle",
Background = "Green",
NavigationDestination = new Uri("Views/UsuarioList.xaml", UriKind.RelativeOrAbsolute)
}
);
this.Tile.Add(
new TileItem()
{
Icon = new PackIconFontAwesome()
{
Kind = PackIconFontAwesomeKind.Apple
},
Text = "Clientes",
Style = "SmallTileStyle",
Background = "Blue",
NavigationDestination = new Uri("Views/ClienteList.xaml", UriKind.RelativeOrAbsolute)
}
);
Classe TileItem
:
internal class TileItem : BindableBase
{
private object _icon;
private string _text;
private string _style;
private string _background;
private DelegateCommand _command;
private Uri _navigationDestination;
public object Icon
{
get { return this._icon; }
set { this.SetProperty(ref this._icon, value); }
}
public string Text
{
get { return this._text; }
set { this.SetProperty(ref this._text, value); }
}
public string Style
{
get { return this._style; }
set { this.SetProperty(ref this._style, value); }
}
public string Background
{
get { return this._background; }
set { this.SetProperty(ref this._background, value); }
}
public ICommand Command
{
get { return this._command; }
set { this.SetProperty(ref this._command, (DelegateCommand)value); }
}
public Uri NavigationDestination
{
get { return this._navigationDestination; }
set { this.SetProperty(ref this._navigationDestination, value); }
}
public bool IsNavigation => this._navigationDestination != null;
}
O problema é que no bloco abaixo, quando eu faço um Binding
para setar a propriedade Style
, não dá certo, pois ele não consegue setar com os nomes que passo por parâmetro. Alguém sabe como me ajudar?
Style:
<ResourceDictionary>
<Style x:Key="LargeTileStyle" TargetType="Controls:Tile">
<Setter Property="Width" Value="300" />
<Setter Property="Height" Value="125" />
<Setter Property="TitleFontSize" Value="16" />
</Style>
<Style x:Key="SmallTileStyle" TargetType="Controls:Tile">
<Setter Property="Width" Value="147" />
<Setter Property="Height" Value="125" />
<Setter Property="TitleFontSize" Value="16" />
</Style>
</ResourceDictionary>
Layout da minha Window:
<Grid>
<ListBox ItemsSource="{Binding Tile}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<controls:Tile
Title="{Binding Text}"
controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource BlackBrush}"
Command="{Binding DataContext.TileClickCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
CommandParameter="{Binding}"
HorizontalTitleAlignment="Left"
Background="{Binding Background}"
Style="{Binding Style}"
TiltFactor="2">
<Image Width="60"
Height="60"/>
<!--<Source="{Binding OmsConnectionTypeId, Converter={StaticResource ConnectionTypeToIconConverter}}"/>-->
</controls:Tile>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>