Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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
C# 禁用WPF中的所有文本框_C#_Wpf - Fatal编程技术网

C# 禁用WPF中的所有文本框

C# 禁用WPF中的所有文本框,c#,wpf,C#,Wpf,我有一种情况,我需要禁用页面上的所有文本框。 为此,我尝试使用下面的代码 private void DrpDwnSelectSemTimeTable_SelectionChanged(object sender, SelectionChangedEventArgs e) { var firstlecture = this.FirstLecture.Children.OfType<TextBox>(); var secondlecture = this

我有一种情况,我需要禁用页面上的所有文本框。 为此,我尝试使用下面的代码

 private void DrpDwnSelectSemTimeTable_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
    var firstlecture = this.FirstLecture.Children.OfType<TextBox>();
    var secondlecture = this.SecondLecture.Children.OfType<TextBox>();
    var thirdlecture = this.ThirdLecture.Children.OfType<TextBox>();
    var fourthlecture = this.FourthLecture.Children.OfType<TextBox>();
    var fifthlecture = this.FifthLecture.Children.OfType<TextBox>();

                    foreach (var item in firstlecture)
                    {
                        item.IsReadOnly = true;
                    }
                    foreach (var item in secondlecture)
                    {
                        item.IsReadOnly = true;
                    }
                    foreach (var item in thirdlecture)
                    {
                        item.IsReadOnly = true;
                    }
                    foreach (var item in fourthlecture)
                    {
                        item.IsReadOnly = true;
                    }
                    foreach (var item in fifthlecture)
                    {
                        item.IsReadOnly = true;
                    }
}
private void drpdwnselectsemtimeline\u SelectionChanged(对象发送方,selectionchangedventargs e)
{
var firsttouch=this.firsttouch.Children.OfType();
var secondtouch=this.secondtouch.Children.OfType();
var thirdlecture=this.thirdlecture.Children.OfType();
var fourthliture=this.fourthliture.Children.OfType();
var fifthlecture=this.fifthlecture.Children.OfType();
foreach(第一堂课中的var项目)
{
item.IsReadOnly=true;
}
foreach(第二堂课中的var项目)
{
item.IsReadOnly=true;
}
foreach(第三结构中的var项目)
{
item.IsReadOnly=true;
}
foreach(第四种体系结构中的var项)
{
item.IsReadOnly=true;
}
foreach(第五体系结构中的var项)
{
item.IsReadOnly=true;
}
}
任何我的XAML

    <Canvas>
            <WrapPanel x:Name="TimeTableMainWrapPanel" Canvas.Left="109" Canvas.Top="195" Height="601" Width="745>
                <TextBox x:Name="txtFirstLctrTime"  Height="24" TextWrapping="Wrap" Width="115"/>
                <TextBox x:Name="txtSecondLctrTime" Height="23" Canvas.Left="594" TextWrapping="Wrap" Canvas.Top="189" Width="115"/>

              <WrapPanel x:Name="TimeTableSubWrapPanel" Canvas.Left="109" Canvas.Top="195" Height="601" Width="745">
                 <WrapPanel x:Name="FirstLecture" Background="#00F0F8FF" Height="392" Width="133" Margin="0,0,10,0">
                    <TextBox x:Name="txtMondayFirstLctr" Width="133" Margin="0" Height="30" FontSize="13" VerticalContentAlignment="Center"/>
                    <TextBox x:Name="txtTuesdayFirstLctr" Width="133" Margin="0,38,0,0" Height="30" FontSize="13" VerticalContentAlignment="Center"/>
                 </WrapPanel>

                <WrapPanel x:Name="SecondLecture" Canvas.Top="220" Background="#00F0F8FF" Canvas.Left="270" Height="466" Width="133" Margin="8,0,10,0">
                    <TextBox x:Name="txtMondaySecondLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                    <TextBox x:Name="txtTuesdaySecondLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                </WrapPanel>

                <WrapPanel x:Name="ThirdLecture" Canvas.Top="219" Background="#00F0F8FF" Canvas.Left="415" Height="466" Width="133" Margin="8,0,10,0">
                    <TextBox x:Name="txtMondayThirdLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                    <TextBox x:Name="txtTuesdayThirdLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                </WrapPanel>

                <WrapPanel x:Name="FourthLecture" Canvas.Top="221" Background="#00F0F8FF" Canvas.Left="562" Height="466" Width="133" Margin="8,0,0,0">
                    <TextBox x:Name="txtMondayFourthLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                    <TextBox x:Name="txtTuesdayFourthLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                </WrapPanel>

                <WrapPanel x:Name="FifthLecture" Canvas.Top="220" Background="#00F0F8FF" Canvas.Left="710" Height="466" Width="135" Margin="18,0,0,0">
                    <TextBox x:Name="txtMondayFifthLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                    <TextBox x:Name="txtTuesdayFifthLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
                </WrapPanel>
            </WrapPanel>
 </Canvas>


将所有文本框放在堆栈面板下,如下所示:

<StackPanel Orientation="Horizontal">
    <StackPanel x:Name="TextboxContainer" Orientation="Horizontal">
        <!-- All textboxes here -->
    </StackPanel>
    <Button Content="Cancel" />
</StackPanel>
所以你们不需要遍历页面上的所有控件,甚至不需要遍历每个文本框。所以对我来说,这是实现目标的更优化、最快的方法

注意:额外的stackpanel将在那里,因此请先查看您的可行性

问我你有什么问题

<StackPanel Orientation="Horizontal">
    <StackPanel x:Name="TextboxContainer" Orientation="Horizontal">
        <!-- All textboxes here -->
    </StackPanel>
    <Button Content="Cancel" />
</StackPanel>
TextboxContainer.IsReadonly = true;