简体   繁体   中英

Custom property in NavigationViewItem

I'm creating a new grid in NavigationViewItem for notifications. But I don't understand how to create a < NavigationViewItem.Notification visible="True" Text="12" > property to use.

I created the design but the text is assigned to all items. I would like to control the properties of notifications (Visible and Text)

图片

How do I manage this? Any help would be appreciated!

<Grid Visibility="Visible" CornerRadius="5, 5, 5, 5" HorizontalAlignment="Right" Width="30" Background="#11FFFFFF" Opacity="1" Height="24" Margin="0,0,15,0">
 <TextBlock Text="17" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,1" Foreground="#FFC5C5C5"/>
</Grid>

Custom property in NavigationViewItem

The default NavigationViewItem does not contain Notification property. You could use TempateControl to custom NavigationViewItem but it is complex. There is easy way implement it that process Visibility with IValueConverter .

    <Grid
        Width="200"
        Height="24"
        Margin="0,0,15,0"
        HorizontalAlignment="Right"
        Background="#11FFFFFF"
        CornerRadius="5, 5, 5, 5"
        Opacity="1"
        Visibility="{Binding MessgeCount, Converter={StaticResource visibilityConverter}}"
        >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <TextBlock Text="{Binding Name}" />
        <TextBlock
            Grid.Column="1"
            Margin="0,0,0,1"
            HorizontalAlignment="Right"
            VerticalAlignment="Center"
            Foreground="#FFC5C5C5"
            Text="{Binding MessgeCount}"
            />
    </Grid>

VisibilityConverter

public class VisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        if ((int)value == 0)
        {
            return Visibility.Collapsed;
        }
        else
        {
            return Visibility.Visible;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

Model class

public class Category : CategoryBase
{
    public string Name { get; set; }
    public string Tooltip { get; set; }
    public Symbol Glyph { get; set; }
    public bool IsEnabled { get; set; }
    public int MessgeCount { get; set; }
}

This is code sample that you could refer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM