none
WPF 如何实现 VS 错误提示的效果 RRS feed

答案

  • 你好 Wangminwei,

    WPF对于错误的提示有一个默认控件 Validation Class,你可以查看 Validation.Errors 和 Validation.ErrorTemplate ,它会在出错误的时候给你提示,一个红框,并且显示错误信息。具体的做法你可以参看完MSDN文档以后看CodeProject上的这个例子:http://www.codeproject.com/Articles/15239/Validation-in-Windows-Presentation-Foundation

    但是这个跟你的要求不符合,如果你想要这种对话框的话,你可能需要自己写自定义控件,比如这里我做了一个透明的窗体并且带了线和显示文字的label:

    <Window x:Class="WpfApplication1.CustomWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="CustomWindow" Height="285.882" Width="421.176" AllowsTransparency="True" WindowStyle="None" Background="#00FFFFFF">
        <Grid>
            <Canvas HorizontalAlignment="Left" Height="100" Margin="30,139,0,0" VerticalAlignment="Top" Width="142">
                <Line
        X1="0" Y1="70"
        X2="130" Y2="0"
        Stroke="Black"
        StrokeThickness="4" Height="90" Width="132" />
    
            </Canvas>
            <Label Content="Label" HorizontalAlignment="Left" Margin="189,108,0,0" VerticalAlignment="Top" Width="199" Height="57"/>
    
        </Grid>
    </Window>
    



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年12月17日 8:53
    版主