jeudi 25 octobre 2018

Add text on image dynamically in WPF with C#

I am trying to achieve some thing below in the image. In the list, I would like to put the text "WS1", "WS2" "WS3" onto the image dynamically in the code depending on the some conditions. I have setup something in xaml. I am not sure if that will work and how to write the code to match the xaml.

       <Style x:Key="AnnotationStyle" TargetType="TextBlock">
        <Setter Property="Background" Value="#70FFFFFF" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="TextAlignment" Value="Center"/>
        <Setter Property="TextWrapping" Value="Wrap"/>
    </Style>
    <DataTemplate x:Key="DisplayImage">
        <StackPanel Width="50">
            <StackPanel Orientation="Horizontal">
                <Image Height="40" Source="{Binding ImageData}" />
                <TextBlock Text="{Binding Description}" Style="{StaticResource AnnotationStyle}"/>
            </StackPanel>
        </StackPanel>
    </DataTemplate>

 <ListView.View>
     <GridView>
         <GridViewColumn CellTemplate="{StaticResource checkbox}"/>
         <GridViewColumn Header="Profile ID" DisplayMemberBinding="{Binding ProfileID}"/>
                <GridViewColumn Header="Monitor 1" DisplayMemberBinding="{Binding DisplayImage}">
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

How do I implement this in the code and does this xaml work? thank you very much in advance.

enter image description here

Aucun commentaire:

Enregistrer un commentaire