用户控件wpf中的访问按钮属性

时间:2011-05-12 08:26:14

标签: c# .net wpf user-controls

我有自定义UserControl。在那个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>

1 个答案:

答案 0 :(得分:2)

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

See this