我想在WPF中的mainWindow中访问我的控件,如按钮或文本框,但我不能这样做.
在Windows窗体应用程序中它很容易,您可以将该控件的修饰符设置为True,并且您可以从该mainWindow的实例到达该控件,但在WPF中,我无法声明公共控件.我怎样才能做到这一点?
我在QtDesigner中使用QtDesinger设计GUI,在QtDesigner中设计我想要的UI后,将其转换为python代码,然后我改变生成的代码在我的python代码中执行一些操作,但是如果我用QtDesigner更改了UI再次将其转换为python代码,我在代码上丢失了以前的更改.
我该如何解决这个问题?
我们可以在python中传播多个文件的类来编写其他文件中的代码吗?
我想要一个类似于复选框的单选按钮,所以我在字典文件中定义了一个样式,如:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCheckBoxLikeRadiobutton">
<Style x:Key="MyRadioButton" TargetType="{x:Type RadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<CheckBox
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=IsChecked, Mode=TwoWay}"
IsHitTestVisible="False" />
<CheckBox
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=IsChecked, Mode=TwoWay}" Opacity="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
并像这样将其合并到 app.xaml 文件中
<Application x:Class="WpfCheckBoxLikeRadiobutton.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCheckBoxLikeRadiobutton"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
然后在我的窗口中使用它
<GroupBox Margin="5" Padding="5">
<StackPanel >
<CheckBox Content="this is checkbox" />
<RadioButton Content="this is first radio button" Style="{DynamicResource MyRadioButton}"/>
<RadioButton Content="this is Second radio button" Style="{DynamicResource …Run Code Online (Sandbox Code Playgroud)