相关疑难解决方法(0)

如何反转BooleanToVisibilityConverter?

BooleanToVisibilityConverter在WPF中使用a 将Visibility控件的属性绑定到a Boolean.这工作正常,但我想要一个控件隐藏如果布尔是true,并显示它是否false.

.net wpf binding visibility

128
推荐指数
8
解决办法
9万
查看次数

WPF绑定:!值

我有按钮:

<Button Content="Stop loading" />
Run Code Online (Sandbox Code Playgroud)

在ViewModel中,我有属性IsLoaded.我不想写属性IsNotLoaded但我想在IsLoaded = true时在绑定和禁用按钮中使用IsLoaded.

如何实现这样的事情:

<Button Content="Stop loading" IsEnabled="{Binding !IsLoaded}" />
Run Code Online (Sandbox Code Playgroud)

PS如果比编写附加属性更难,我将使用IsNotLoaded属性.

c# wpf binding

19
推荐指数
4
解决办法
3万
查看次数

WPF - 是否有可能否定数据绑定表达式的结果?

我知道这很好用:

<TextBox IsEnabled="{Binding ElementName=myRadioButton, Path=IsChecked}" />
Run Code Online (Sandbox Code Playgroud)

...但我真正想做的是否定类似于下面的结合表达式的结果(伪代码).这可能吗?

<TextBox IsEnabled="!{Binding ElementName=myRadioButton, Path=IsChecked}" />
Run Code Online (Sandbox Code Playgroud)

.net c# data-binding wpf

10
推荐指数
2
解决办法
8616
查看次数

在C#中运行时取消选中复选框时禁用文本框

我有一个CheckBox和一个TextBox.在运行时期间,
如果CheckBox已选中,则启用TextBox.

我使用以下代码完成了它

private void checkTime_Checked(object sender, RoutedEventArgs e)
{
    if (checkTime.IsChecked == true)
    {
        txtTime_SR.IsEnabled = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要做的是,在运行时取消选中CheckBox时禁用TextBox.

这样做的任何想法?

c# wpf

5
推荐指数
2
解决办法
1万
查看次数

如何使用XAML在Panel或GroupBox等整个容器上设置IsReadOnly/IsEnabled?

我有一个MVVM应用程序包含多个视图,其中包含一些IsReadOnly基于用户权限,查看/编辑模式和对象状态的复杂规则.

我想设置IsReadOnly和/或IsEnabled用于控制的整个组的属性在同一容器(GroupBox/ StackPanel/ Grid/ UserControl/等).此属性的值将在ViewModel中定义.

我有3-6不同的SomeGroupIsReadOnly每用户控件的属性(也像大量输入控件TextBox,RadioButtons,ComboBoxes和一些DataGrids),我正在寻找一个通用的,MVVM-友好的解决方案,这将让我重新使用绑定在每个容器而不是分别为每个单独的控件指定它们.

如何使用XAML在Panel或GroupBox等容器内的所有控件上设置IsReadOnly/IsEnabled?

WPF似乎不支持这种开箱即用的...

编辑

我忘了提到为容器设置IsEnabled会禁用TextBoxes的一个重要功能 - 能够复制它们的内容.我需要他们处于IsReadOnly=true状态.如果有一个工作方法,那么我的问题将得到解决.

c# wpf xaml mvvm isenabled

4
推荐指数
2
解决办法
1万
查看次数

如何在WPF中绑定布尔型逆属性与如何在WPF中绑定布尔型逆属性

我有个问题。 如何在WPF中绑定反向布尔属性?

当我与ResourceDictionary一起使用时,它会给出运行时错误。找不到InverseBooleanConverter。

XMAL如下:

<UserControl x:Class="SMTF.MasterDataView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SMTF" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="466" d:DesignWidth="483">
<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../AppResource.xaml" />
            <ResourceDictionary Source="../DefaultStyle.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>
    <Grid>
    <StackPanel  HorizontalAlignment="Left" Margin="200,12,0,0" Name="stkMain" VerticalAlignment="Top" >
        <Grid Margin="4">
            <ContentControl Visibility="{Binding IsChecked, ElementName=VisibilityToggle, Converter={StaticResource InverseBooleanConverter}}" >
                <Border Grid.Column="2" Style="{StaticResource MainBorderStyle}">
                    <HeaderedContentControl   Content="{Binding Path=WorkspaceView}" ContentTemplate="{StaticResource WorkspacesTemplate}" Header="View" Style="{StaticResource MainHCCStyle}"/>
                </Border>
            </ContentControl>
        </Grid>
        <Grid DockPanel.Dock="Bottom" Margin="0,2,4,2">
            <TextBlock HorizontalAlignment="Right">

               <ToggleButton  x:Name="VisibilityToggle" Focusable="False" Style="{StaticResource SMToggle}"  Command ="{Binding ShowNew}" >

                </ToggleButton>
               <!--<ToggleButton x:Name="VisibilityToggle"   Background="Transparent" Command ="{Binding ShowNew}" >
                     <Image …
Run Code Online (Sandbox Code Playgroud)

wpf styles

3
推荐指数
1
解决办法
2万
查看次数

数据绑定和应用转换器时取反布尔属性

在XAML绑定标记中可以否定布尔属性。不知道这是正确的描述。例如,我使用一个内置的转换器来基于其是否处于活动状态来设置窗口边框控件的可见性。

<Border BorderBrush="{StaticResource BorderColorBrush}" 
        BorderThickness="1" 
        Visibility="{Binding IsActive, 
                     RelativeSource={RelativeSource FindAncestor, 
                                     AncestorType={x:Type Window}}, 
                     Converter={StaticResource bool2VisibilityConverter}}" />
Run Code Online (Sandbox Code Playgroud)

与我相反的是,如果Window处于活动状态,我希望将Visibility设置为false。这只是一个例子,但是我遇到了其他情况,在这种情况下可以应用“!” 转换为股票转换器正在评估的布尔属性,因此我不必编写自定义变量。

data-binding wpf ivalueconverter

2
推荐指数
1
解决办法
2021
查看次数

标签 统计

wpf ×7

c# ×4

.net ×2

binding ×2

data-binding ×2

isenabled ×1

ivalueconverter ×1

mvvm ×1

styles ×1

visibility ×1

xaml ×1