我在将WPF程序从“Visual Studio Express 2013 for Windows Desktop”移动到“Visual Studio Community 2015”时遇到问题。XAML中的WPF程序问题无法正确显示按钮
我的原始WPF程序创建于“VS Express 2013 for Windows Desktop”。它依赖于能够将网格嵌入按钮。在该网格上(按钮内),我会放置矩形形状。它在VS Express 2013中正常工作,但在VS社区2015中无法正常工作。
下面的示例创建于VS Express 2013。它正确地显示了一个红色边框矩形和一个带白色十字的黑色按钮。
<Window x:Class="TestErrors.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="200" Width="200">
<Canvas>
<Rectangle
Stroke="Red"
StrokeThickness="10"
Width="50"
Height="50"
Canvas.Left="75"
Canvas.Top="20"/>
<Button
Width="0"
Height="0"
Canvas.Left="100"
Canvas.Top="100">
<Canvas>
<Rectangle
Fill="Black"
Width="30"
Height="30"
Canvas.Left="-15"
Canvas.Top="-15"/>
<Rectangle
Fill="White"
Width="4"
Height="20"
Canvas.Left="-2"
Canvas.Top="-10"/>
<Rectangle
Fill="White"
Width="20"
Height="4"
Canvas.Left="-10"
Canvas.Top="-2"/>
</Canvas>
</Button>
</Canvas>
</Window>
为VS表达上述图像2013是正确的......白十字的黑色按钮正确显示。
以下示例中的Visual Studio Community 2015中的相同XAML仅显示红色矩形。它没有按我的预期工作。
<Window x:Class="TestErrors.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:local="clr-namespace:TestErrors"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Canvas>
<Rectangle
Stroke="Red"
StrokeThickness="10"
Width="50"
Height="50"
Canvas.Left="75"
Canvas.Top="20"/>
<Button
Width="0"
Height="0"
Canvas.Left="100"
Canvas.Top="100">
<Canvas>
<Rectangle
Fill="Black"
Width="30"
Height="30"
Canvas.Left="-15"
Canvas.Top="-15"/>
<Rectangle
Fill="White"
Width="4"
Height="20"
Canvas.Left="-2"
Canvas.Top="-10"/>
<Rectangle
Fill="White"
Width="20"
Height="4"
Canvas.Left="-10"
Canvas.Top="-2"/>
</Canvas>
</Button>
</Canvas>
</Window>
凡与白十字内的黑色按钮?什么改变了我的原始代码?
是的,我知道高度和宽度设置为0.并且它在VS Express 2013中工作正常。我有一个编写的巨大程序,它依靠这种方式处理按钮。我不知道为什么VS和WPF的新版本中的行为发生了变化。 – user3130331
所有更改都记录在这里:https://msdn.microsoft.com/en-us/library/hh367887(v=vs.110).aspx –
谢谢彼得...我会看看... – user3130331