gpt4 book ai didi

c# - 在用户控件 wpf 中访问按钮的属性

转载 作者:太空宇宙 更新时间:2023-11-03 11:36:54 25 4
gpt4 key购买 nike

我有一个自定义用户控件。在那个 UserControl 中,我有一些按钮、组合框、文本框。当我在 wpf 应用程序中使用它时,我希望能够更改按钮的背景和大小...我有所有控件的名称,但是当我尝试在 wpf 应用程序中访问它们时,我什至看不到它们。

这是用户控件 -

<UserControl x:Class="MyUserControl.UserControl"
Name="MyCustomUSerControl"
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="600" d:DesignWidth="620" Width="Auto" Height="Auto">
<Grid Width="Auto" Height="Auto" Background="LavenderBlush" x:Name="Grid_MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Expander Height="Auto" Width="Auto" Header="Filter" FontFamily="Arial Rounded MT">
<Border CornerRadius="12" BorderThickness="2" Margin="5" BorderBrush="CornflowerBlue" Height="Auto" Width="Auto">
<StackPanel Orientation="Horizontal" Height="Auto" Width="Auto" x:Name="StackPanel_ManinStackInExpander" >
<StackPanel x:Name="StackPanel_Column" Height="Auto" Width="Auto" Margin="10,10,0,10">
<Label x:Name="Label_Column" Content="Column" Height="22" Width="70" Margin="0,0,0,0" HorizontalAlignment="Left" FontFamily="Rockwell" FontWeight="Normal"/>
<ComboBox x:Name="ComboBox_Columns" Background="Transparent" Height="Auto" Width="Auto" MinWidth="100" FontFamily="Bernard MT"/>
<Label x:Name="Label_Like" Content="Like" Height="22" Width="70" Margin="0,0,0,0" HorizontalAlignment="Left" FontFamily="Rockwell" FontWeight="Normal"/>
<TextBox Background="Transparent" Height="Auto" Width="Auto" FontFamily="Bernard MT" MinWidth="100" x:Name="TextBox_Like"/>
<StackPanel Orientation="Horizontal">
<StackPanel>
<Label x:Name="Label_Operation" Content="Operation" FontFamily="Rockwell"/>
<ComboBox x:Name="ComboBox_Operation" Background="Transparent" Width="50" HorizontalAlignment="Left" Margin="5,0,0,0">
<ComboBoxItem Content="&lt;"> </ComboBoxItem>
<ComboBoxItem Content=">"></ComboBoxItem>
<ComboBoxItem Content="="></ComboBoxItem>
<ComboBoxItem Content=">="></ComboBoxItem>
<ComboBoxItem Content="&lt;="></ComboBoxItem>
<ComboBoxItem Content="&lt;>"></ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Margin="10,0,0,0">
<Label Content="Value" x:Name="Label_Value" FontFamily="Rockwell"/>
<TextBox Background="Transparent" Width="Auto" Height="Auto"/>
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Height="Auto" Width="Auto" Margin="10,10,0,10">
<Button x:Name="Button_AND" Background="LightGoldenrodYellow" Content="AND" Height="20" Width="70" Margin="10" FontFamily="Californian FB" FontWeight="Bold"/>
<Button x:Name="Button_OR" Background="LightGoldenrodYellow" Content="OR" Height="20" Width="70" Margin="10,0,10,10" FontFamily="Californian FB" FontWeight="Bold"/>
</StackPanel>
<ListView Margin="10" MinWidth="200" Background="Transparent" BorderThickness="1"></ListView>
<StackPanel Margin="0,10,10,10">
<Button x:Name="Button_Enclose" Background="LightGoldenrodYellow" Width="120" Height="25" Margin="10" Content="( )" FontFamily="Californian FB" FontWeight="Bold" FontSize="14"/>
<Button x:Name="Button_Filter" Background="LightGoldenrodYellow" Width="120" Height="25" Margin="10,45,10,0" Content="FIlter" FontFamily="Californian FB" FontWeight="Bold" FontSize="14"/>
</StackPanel>
</StackPanel>

</Border>
</Expander>
</Grid>

最佳答案

使用 C# 时,将 x:FieldModifier="public"添加到要公开的元素。

See this

关于c# - 在用户控件 wpf 中访问按钮的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5975301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com