2 回答

TA贡献1801条经验 获得超16个赞
您正在使用 WPF。您提供的最后一个示例链接使用 WinForms。WinForms 在按钮上提供属性 Text 而 WPF 按钮没有。如果要设置 WPF 按钮的内容,应使用 Content 属性。
像这样:
var button = new Button();
button.Content = "Click here";
或者使用对象初始值设定项:
var button = new Button {Content = "Click here"};

TA贡献1820条经验 获得超9个赞
我认为您正在做的可能应该是用户控件而不是自定义控件。
也许是这样的:
<UserControl x:Class="wpf_99.UserControl1"
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"
xmlns:local="clr-namespace:wpf_99"
mc:Ignorable="d"
Height="25"
>
<UserControl.Resources>
<Style TargetType="Button">
<Setter Property="Width" Value="92"/>
<Setter Property="Margin" Value="2"/>
</Style>
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<Button Name="StartButton" Content="Start"/>
<Button Name="StopButton" Content="Stop"/>
<Button Name="ResetButton" Content="Reset"/>
</StackPanel>
</UserControl>
用法:
<Window
...
xmlns:local="clr-namespace:wpf_99"
>
<Grid>
<local:UserControl1 HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
您可能会发现这很有用:
https://social.technet.microsoft.com/wiki/contents/articles/32610.wpf-layout-lab.aspx
- 2 回答
- 0 关注
- 321 浏览
添加回答
举报