Alert View Template |
User can change the complete look and feel of the Alert View by building custom xaml template. The Alert View is bounded with an AlertViewModel object
Any custom Alert xaml template must have the suffix Alert. For example if you name your Alert template as MyAlert, then the dataTemplate's key will be MyAlertAlert.
<DataTemplate x:Key="MyAlertAlert"> <!-- design your template here --> </DataTemplate>
xmlns:bControls="clr-namespace:SharpCharts.Base.Controls;assembly=SharpCharts.Base" xmlns:bCommon="clr-namespace:SharpCharts.Base.Common;assembly=SharpCharts.Base" xmlns:bOrder="clr-namespace:SharpCharts.Base.Order;assembly=SharpCharts.Base" xmlns:bData="clr-namespace:SharpCharts.Base.Data;assembly=SharpCharts.Base"
<DataTemplate x:Key="selectedAlertTemplate" > <TextBlock Text="{Binding Message}" Foreground="{Binding Foreground}" Background="{Binding Background}" FontWeight="SemiBold" TextWrapping="Wrap" /> </DataTemplate> <DataTemplate x:Key="defaultAlertTemplate"> <Grid Background="{Binding Background}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Text="{Binding Time}" Margin="3" Foreground="{Binding Foreground}" /> <TextBlock Grid.Column="1" Text="{Binding Priority}" Margin="3" Foreground="{Binding Foreground}" /> <TextBlock Grid.Column="2" Text="{Binding Instrument.DisplayName}" Margin="3" Foreground="{Binding Foreground}" /> <TextBlock Grid.Column="3" Text="{Binding Message}" Margin="3" Foreground="{Binding Foreground}" /> </Grid> </DataTemplate> <DataTemplate x:Key="DefaultAlert"> <Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <ListBox ItemsSource="{Binding Alerts}" SelectedItem="{Binding SelectedAlertItem}" SelectionMode="Single" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="ContentTemplate" Value="{StaticResource defaultAlertTemplate}" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="ContentTemplate" Value="{StaticResource selectedAlertTemplate}" /> </Trigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle> </ListBox> </Grid> </DataTemplate>