WPF在运行时基于配置文件对StackPanel中的XAML元素进行排序

问题描述

我正在使用带有Caliburn.Micro的MVVM模式开发WPF应用程序 我有一个配置文件,其中包含XAML元素应在StackPanel内部的位置

# in this case RU_ELEMENT should be at the top,EN_ELEMENT second and DE_ELEMENT last
EN_ELEMENT = 1
DE_ELEMENT = 2
RU_ELEMENT = 0

这似乎很基本,但我找不到解决方法。我发现了这个线程:change the children index of stackpanel in wpf,但是对于我所追求的来说,以这种方式更改它似乎太复杂了。我只需要从变量中设置元素的索引。我觉得应该有一种更简单的方法。我还可以使用其他一些可能比StackPanel更合适的布局面板。

XAML:


<!--     Language1 -->
<TextBlock Text="English" Foreground="DarkGray" FontSize="16"/>
<TextBox
    VerticalAlignment="Top"
    Height="150"
    Text="{Binding SelectedItem.ValueEN,UpdateSourceTrigger=PropertyChanged}"
    cm:Message.Attach="[Event GotFocus] = [Action FocusedTextBox('english')]" />

<!--     Language2 -->
<TextBlock Text="German" Foreground="DarkGray" FontSize="16"/>
<TextBox
    VerticalAlignment="Top"
    Height="150"
    Text="{Binding SelectedItem.ValueDE,UpdateSourceTrigger=PropertyChanged}"
    cm:Message.Attach="[Event GotFocus] = [Action FocusedTextBox('german')]" />

在旁注:与以前的所有语言(Java,Python,JS)相比,我发现WPF和C#通常没有太多的讨论和“如何做”指南,因此在线研究事物通常是徒劳的为我而死。我不确定为什么会这样,因为C#是一种非常流行的语言,但是我真的很难在网上寻求帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)