如何以编程方式访问 d:DesignHeight 和 d:DesignWidth? 使用 C#
<UsеrControl x:Class="MySpace.MyControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="360">
最佳答案
您不能以编程方式“访问”它。
Documentation for the mc:Ignorable
attribute明确指出:
Specifies which XML namespace prefixes encountered in a markup file may be ignored by a XAML processor
这意味着 XAML 编译器将忽略此属性指示的命名空间内的 XML 属性和元素,因此在运行时无法访问。
此外,在基于 XAML 的技术中,无需在过程代码中弄乱 UI。你走错了路。
不要在 WPF 的过程代码中创建或操作 UI 元素。这就是 XAML 的用途。
如果您需要更详细的答案,请在此处提供有关您尝试执行的操作的其他信息。
关于c# - 如何以编程方式访问 d : DesignHeight and d: DesignWidth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20222113/