Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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中的radiobutton单击上生成动态文本框_C#_.net_Wpf_Dynamic_Mvvm - Fatal编程技术网

C# 无法在WPF中的radiobutton单击上生成动态文本框

C# 无法在WPF中的radiobutton单击上生成动态文本框,c#,.net,wpf,dynamic,mvvm,C#,.net,Wpf,Dynamic,Mvvm,我正在开发一个WPF应用程序,我必须首先生成4个单选按钮,一旦完成,我需要在每次按钮点击时生成文本框和标签 生成4个包含不同内容的单选按钮 单击每个按钮时,根据单击的按钮生成8个具有不同内容的标签,并生成64个文本框,这些文本框是只读的,每个标签有8个与其关联的文本框。i、 e.8 x 8 我通过以下方式取得了一定程度的成功: XAML: 在我的xaml中,我将网格划分为两行。第一行将有4个单选按钮。第二行将分为两列,其中第一列将有8个动态标签,第二列将有64个文本框。i、 e.每行8个 &

我正在开发一个WPF应用程序,我必须首先生成4个单选按钮,一旦完成,我需要在每次按钮点击时生成文本框和标签

  • 生成4个包含不同内容的单选按钮
  • 单击每个按钮时,根据单击的按钮生成8个具有不同内容的标签,并生成64个文本框,这些文本框是只读的,每个标签有8个与其关联的文本框。i、 e.8 x 8
我通过以下方式取得了一定程度的成功:

XAML:

在我的xaml中,我将网格划分为两行。第一行将有4个单选按钮。第二行将分为两列,其中第一列将有8个动态标签,第二列将有64个文本框。i、 e.每行8个

<Grid Grid.Row="0">                     

        <ItemsControl ItemsSource="{Binding Children}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" >
                        <RadioButton Content="{Binding RadioBase}" Margin="0,10,0,0" IsChecked="{Binding BaseCheck}" GroupName="SlotGroup" />                            
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <Button Content="Refresh Regs" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Margin="0" Width="100" Height="25" />
    </Grid>

<Grid Grid.Row="1">            

        <ItemsControl ItemsSource="{Binding Children}" Grid.Column="0">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <ItemsControl Visibility="{Binding IsRegisterItemsVisible, Converter={StaticResource BoolToVisibilityConv}}" ItemsSource="{Binding RegisterLabels}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="50,20,0,0">
                                        <TextBlock Text="{Binding}"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <ItemsControl ItemsSource="{Binding Children}" Grid.Column="1">
            // Textbox here
        </ItemsControl>
    </Grid>
以下是截图:
请帮助:)

对此,我会采取不同的方法:

  • 您可以使用无线电虚拟机,但它们也应该是一个子集合,包含网格中的每个“行”,其中依次包含一个“Title”属性(您放在标签上的属性)和一个包含8个字符串值的列表,这些字符串值将显示在您的文本框中。比如:
主视图模型

  • ->无线电虚拟机列表
  • ->选定的无线电虚拟机
  • ->子“行”列表
  • 划船
  • ->行标签(字符串属性)
  • ->字符串值列表

  • 然后,您只需要2个ItemsControl:1来绘制所有“行”和每行的内部,一个标签,第二个ItemsControl(ItemsPanelTemplate中有一个水平堆叠面板来绘制文本框)

    对此,我会采取不同的方法:

    • 您可以使用无线电虚拟机,但它们也应该是一个子集合,包含网格中的每个“行”,其中依次包含一个“Title”属性(您放在标签上的属性)和一个包含8个字符串值的列表,这些字符串值将显示在您的文本框中。比如:
    主视图模型

  • ->无线电虚拟机列表
  • ->选定的无线电虚拟机
  • ->子“行”列表
  • 划船
  • ->行标签(字符串属性)
  • ->字符串值列表

  • 那么你只需要两个ItemsControl:1来绘制所有“行”和每行的内部,一个标签,第二个ItemsControl(ItemsPanelTemplate中有一个水平堆叠面板来绘制文本框)

    你昨天没有问这个问题吗?@Prayos:没有。那是[我记得昨天看到了这个问题。所以,我查看了我的历史记录,发现现在是一个被删除的问题。所以,虽然我无法用一张破名单证明任何事情,但我肯定你昨天问了这个问题。@Prayos:这对我来说似乎是一个艰难的局面。如果你能帮我解决这个问题,我将不胜感激。你没有问这个问题吗昨天的事?@Prayos:不,那是真的[我记得昨天看到了这个问题。所以,我查看了我的历史记录,发现现在是一个删除的问题。所以,虽然我无法用一个破名单证明任何事情,但我肯定你昨天问了这个问题。@Prayos:这对我来说似乎是一个艰难的局面。如果你能帮我解决这个问题,我将不胜感激。这似乎是一个好主意a、 如果您能用代码演示,我将不胜感激:)这似乎是个好主意。如果您能用代码演示,我将不胜感激:)
    public ObservableCollection<FPGAViewModel> Children { get; set; }
    
        public FPGARadioWidgetViewModel()
        {
            Children = new ObservableCollection<FPGAViewModel>();
            Children.Add(new FPGAViewModel() { RadioBase = "Base 0x0", ID = 0 });
            Children.Add(new FPGAViewModel() { RadioBase = "Base 0x40", ID = 1 });
            Children.Add(new FPGAViewModel() { RadioBase = "Base 0x80", ID = 2 });
            Children.Add(new FPGAViewModel() { RadioBase = "Base 0xc0", ID = 3 });            
        }
    
    private bool sBaseCheck;
        public bool BaseCheck
        {
            get { return this.sBaseCheck; }
            set
            {
                this.sBaseCheck = value;
                Generatelabels(this, ID);
                this.OnPropertyChanged("BaseCheck");
            }
        }
    
        private static void Generatelabels(FPGAViewModel currentItem, int index)
        {
            int m_baseRegister = 0;
    
            if (index == 0)
            {                
                for (int i = 0; i < 0x40 / 8; i++)
                {
                    int reg = (i * 8) + m_baseRegister;
                    currentItem.RegisterLabels[i] = "Reg 0x" + reg.ToString("X");
                    currentItem.IsRegisterItemsVisible = true;
                }
            }
            else if (index == 1)
            {
                m_baseRegister = 0x40 * index;
                for (int i = 0; i < 0x40 / 8; i++)
                {
                    int reg = (i * 8) + m_baseRegister;
                    currentItem.RegisterLabels[i] = "Reg 0x" + reg.ToString("X");
                    currentItem.IsRegisterItemsVisible = true;
                }
            }
            // Similarly for Index 2 and Index = 3
        }
    
        private string[] registerLabels = new string[8];
        public string[] RegisterLabels { get { return registerLabels; } }
    
        private bool isRegisterItemsVisible = false;
        public bool IsRegisterItemsVisible
        {
            get { return isRegisterItemsVisible; }
            set
            {
                isRegisterItemsVisible = value;
                OnPropertyChanged("IsRegisterItemsVisible");
                OnPropertyChanged("RegisterLabels");
            }
        }        
    
        private string _RadioBase;
        public string RadioBase
        {
            get; set;
        }
    
        private int _ID;
        public int ID
        {
            get; set;
        }
    
    for(i = 0; i < 0x40; i++)
    {
        m_registerGetValue[i] = new TextEditor();
        m_registerGetValue[i]->setReadOnly(true);
        addAndMakeVisible(m_registerGetValue[i]);
    }