【发布时间】:2016-06-11 00:52:47
【问题描述】:
我在将 WPF 程序从“Visual Studio Express 2013 for Windows Desktop”移动到“Visual Studio Community 2015”时遇到问题。
我最初的 WPF 程序是在“VS Express 2013 for Windows Desktop”中创建的。它依赖于能够将 Grid 嵌入到 Button 中。在那个网格上(在按钮内),我会放置矩形。它在 VS Express 2013 中运行良好,但在 VS Community 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 Express 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>
里面有白色十字的黑色按钮在哪里?什么改变了我的原始代码?
【问题讨论】:
标签: wpf visual-studio xaml