Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何用xaml编写代码_Wpf_Vb.net_Xaml - Fatal编程技术网

Wpf 如何用xaml编写代码

Wpf 如何用xaml编写代码,wpf,vb.net,xaml,Wpf,Vb.net,Xaml,是否可以在.xaml文件而不是.xaml.vb文件中编写下面的代码 Private Sub combx_Auswahl_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles combx_Auswahl.SelectionChanged If combx_Auswahl.SelectedIndex = 0 Then lbl_NeueMailAdresse.Visibility =

是否可以在.xaml文件而不是.xaml.vb文件中编写下面的代码

Private Sub combx_Auswahl_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles combx_Auswahl.SelectionChanged
    If combx_Auswahl.SelectedIndex = 0 Then
        lbl_NeueMailAdresse.Visibility = Visibility.Visible
        txtbx_neueEmail.Visibility = Visibility.Visible
        btn_BestaetigeBearbeitung.IsEnabled = True
        btn_AbbruchBearbeitung.IsEnabled = True
    Else
        lbl_NeueMailAdresse.Visibility = Visibility.Hidden
        txtbx_neueEmail.Visibility = Visibility.Hidden
        btn_BestaetigeBearbeitung.IsEnabled = True
        btn_AbbruchBearbeitung.IsEnabled = True
    End If
End Sub
My.xaml:

<Button x:Name="btn_BackToMainWindow" Content="zurück" HorizontalAlignment="Left" VerticalAlignment="Top" 
Width="150" Margin="37,539,0,0" Height="23"/>
<Button x:Name="btn_AbbruchBearbeitung" Content="abbrechen" HorizontalAlignment="Left" VerticalAlignment="Top" 
Width="150" Margin="205,460,0,0" Height="23"/>
<Button x:Name="btn_BestaetigeBearbeitung" Content="bestätigen" HorizontalAlignment="Left" Margin="37,460,0,0" VerticalAlignment="Top" 
Width="150" Height="23"/>
<ComboBox x:Name="combx_Auswahl" HorizontalAlignment="Left" Margin="37,219,0,0" VerticalAlignment="Top" Width="318"/>

如果所有控件都属于同一名称范围,则可以使用带有数据触发器的样式:

<Window.Resources>
    <Style x:Key="style" TargetType="Control">
        <Setter Property="Visibility" Value="Hidden" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding SelectedIndex, ElementName=combx_Auswahl}" Value="0">
                <Setter Property="Visibility" Value="Visible" />
            </DataTrigger>
        </Style.Triggers>

    </Style>

    <Style x:Key="buttonStyle" TargetType="Button">
        <Setter Property="IsEnabled" Value="False" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding SelectedIndex, ElementName=combx_Auswahl}" Value="0">
                <Setter Property="IsEnabled" Value="True" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
...
<ComboBox x:Name="combx_Auswahl">
    <ComboBoxItem>1</ComboBoxItem>
    <ComboBoxItem>2</ComboBoxItem>
    <ComboBoxItem>3</ComboBoxItem>
</ComboBox>

<Label x:Name="lbl_NeueMailAdresse" Style="{StaticResource style}" />
<TextBox x:Name="txtbx_neueEmail" Style="{StaticResource style}" />
<Button Content="Button" x:Name="btn_BestaetigeBearbeitung" Style="{StaticResource buttonStyle}" />

...
1.
2.
3.

如果所有控件都属于同一名称范围,则可以使用带有数据触发器的样式:

<Window.Resources>
    <Style x:Key="style" TargetType="Control">
        <Setter Property="Visibility" Value="Hidden" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding SelectedIndex, ElementName=combx_Auswahl}" Value="0">
                <Setter Property="Visibility" Value="Visible" />
            </DataTrigger>
        </Style.Triggers>

    </Style>

    <Style x:Key="buttonStyle" TargetType="Button">
        <Setter Property="IsEnabled" Value="False" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding SelectedIndex, ElementName=combx_Auswahl}" Value="0">
                <Setter Property="IsEnabled" Value="True" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
...
<ComboBox x:Name="combx_Auswahl">
    <ComboBoxItem>1</ComboBoxItem>
    <ComboBoxItem>2</ComboBoxItem>
    <ComboBoxItem>3</ComboBoxItem>
</ComboBox>

<Label x:Name="lbl_NeueMailAdresse" Style="{StaticResource style}" />
<TextBox x:Name="txtbx_neueEmail" Style="{StaticResource style}" />
<Button Content="Button" x:Name="btn_BestaetigeBearbeitung" Style="{StaticResource buttonStyle}" />

...
1.
2.
3.


@mm8添加了xaml,还需要更多吗?我只剪了旧的lines@Raizzen:您可以这样做,只需使用
触发器即可。MSDN在这方面有很多例子,所以我不会用相同的琐事来污染so答案部分。@code4life ok iam sry。我不知道该找什么名字,我会试试看triggers@Raizzen:看看我的答案。@Raizzen:别担心,伙计。我并不是在说脏话,我只是真的很讨厌把完全相同的材料贴在上面。这通常会适得其反。而且,URL链接多年来往往会变成死链接,而谷歌总是需要帮助的好朋友。@mm8添加了xaml,还需要更多吗?我只剪了旧的lines@Raizzen:您可以这样做,只需使用
触发器即可。MSDN在这方面有很多例子,所以我不会用相同的琐事来污染so答案部分。@code4life ok iam sry。我不知道该找什么名字,我会试试看triggers@Raizzen:看看我的答案。@Raizzen:别担心,伙计。我并不是在说脏话,我只是真的很讨厌把完全相同的材料贴在上面。这通常会适得其反。此外,URL链接多年来往往会变成死链接,而谷歌总是一个需要帮助的好朋友。我已经对我的活动发表了评论,并尝试了我们的xaml更改,但如果我在启动程序时更改组合框的SelectedIndex,则什么也不会发生。您是否将“combx_Auswahl”更改为“combx_Unzustellbalmailauswahl”或任何您的控件?名称区分大小写。不,iam sry我发布了错误的组合框xaml代码。是否必须删除中的可见性=“隐藏”?我刚刚加了“风格”{。。。"是的。您只能在样式中设置可见性属性。请参阅我的示例标记。啊,我明白了!现在它工作得很好!但我对您的代码有一个问题:为什么要使用控件?而不是标签或文本框?如果控件代表所有内容,为什么按钮的额外样式我已经注释了我的事件并尝试了您的xaml更改,但如果更改当我启动程序时,选择组合框的索引。您是否将“combx_Auswahl”更改为“combx_unzustellbalmailauswahl”或任何您的控件名称?名称区分大小写。否,我发布了错误的组合框xaml代码。我是否必须删除中的可见性=“隐藏”?我刚刚添加了“Style={。。。“是的。您只能在样式中设置可见性属性。请参阅我的示例标记。啊,我明白了!现在它工作得很好!但我对您的代码有一个问题:为什么是控件?而不是标签或文本框?如果控件代表所有内容,为什么要为按钮添加额外的样式?”