繁体   English   中英

WPF:Mahapps Metro 水印未显示

[英]WPF: Mahapps Metro Watermark is not showing up

我正在开发一个程序,并且在设置中我希望水印告诉用户他可以在那里插入什么。 我使用了 Mahapps Metro,但水印没有出现,所以我创建了一个只有一个文本框的空白项目,但它仍然没有出现。

我的代码:

<Controls:MetroWindow x:Class="TestWPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
    xmlns:local="clr-namespace:TestWPF"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">

    <Grid Background="White">
        <TextBox Controls:TextBoxHelper.Watermark="TestWater" Height="25" Width="200"/>
    </Grid>
</Controls:MetroWindow>

结果:

在此处输入图像描述

(背景实际上是“小麦”,使文本框更明显)

我错过了什么,为什么它不起作用?

将此添加到您的 WPF 项目的 App.xaml 中。

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

我已经尝试过了,这在此之后工作正常。

Go 通过此处提供的文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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