0

在此处输入图像描述我有一个 ComboEdit,其中显示了 Country List。在表单上,​​它们是一个 ADDRESS 选项卡,在选择 ComboEdit 值时设置为活动状态。ADDRESS 选项卡上控件的位置必须根据指定的布局进行更改(我们可以在此处使用数据库来根据所选国家/地区存储布局)。

我想根据从组合编辑中选择的公司指定的订单动态显示地址格式和控件。请参阅不同的地址格式:http: //msdn.microsoft.com/en-us/library/cc195167.aspx

我想根据所选国家/地区更改控件的更改位置。有什么建议/想法吗? 目前我正在使用两个不同的网格并根据国家价值使可见/隐藏。这对于一两个国家来说是可以的,但不可能添加那么多网格,所以希望将其存储到数据库中。请建议我正确的方法...!

<Grid Name="grdGroupA" Visibility="Hidden" Margin="0,0,95,21" HorizontalAlignment="Right" Width="714">
                        <Label Content="Honorific"  HorizontalAlignment="Left" Margin="18,27,0,0" VerticalAlignment="Top"/>
                        <dxe:TextEdit Name="txtAHonorific" HorizontalAlignment="Left" Margin="134,31,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95" LostFocus="txtAHonorific_LostFocus"/>
                        <dxe:TextEdit Name="txtAFirstName" HorizontalAlignment="Left" Margin="309,31,0,0" VerticalAlignment="Top" Width="64" LostFocus="txtAFirstName_LostFocus"/>
                        <Label Content="First Name"  HorizontalAlignment="Left" Margin="242,27,0,0" VerticalAlignment="Top"/>
                        <dxe:TextEdit Name="txtAMiddleName" Margin="0,31,185,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="64" LostFocus="txtAMiddleName_LostFocus"/>
                        <Label Content="Middle Name"  HorizontalAlignment="Left" Margin="378,27,0,0" VerticalAlignment="Top"/>
                        <dxe:TextEdit Name="txtALastName" HorizontalAlignment="Right" Margin="0,31,35,0" VerticalAlignment="Top" Width="64" LostFocus="txtALastName_LostFocus"/>
                        <Label Content="Last Name" Margin="0,27,99,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="66" RenderTransformOrigin="-0.045,0.577"/>
                        <Label Content="Company Name"  HorizontalAlignment="Left" Margin="18,58,0,0" VerticalAlignment="Top" Width="100"/>
                        <dxe:TextEdit Name="txtACompanyName" HorizontalAlignment="Left" Margin="134,58,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95"/>
                        <Label Content="Address1"  HorizontalAlignment="Left" Margin="18,84,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtAAddress1" HorizontalAlignment="Left" Margin="134,85,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95" LostFocus="txtAAddress1_LostFocus"/>
                        <Label Content="Address2"  HorizontalAlignment="Left" Margin="18,108,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtAAddress2" HorizontalAlignment="Left" Margin="134,112,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95" LostFocus="txtAAddress2_LostFocus"/>
                        <Label Content="City"  HorizontalAlignment="Left" Margin="18,135,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtACity" HorizontalAlignment="Left" Margin="134,139,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95" LostFocus="txtACity_LostFocus"/>
                        <Label Content="State"  HorizontalAlignment="Left" Margin="242,135,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtAState" HorizontalAlignment="Left" Margin="290,135,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95" LostFocus="txtAState_LostFocus"/>
                        <Label Content="Postal Code"  HorizontalAlignment="Left" Margin="410,131,0,0" VerticalAlignment="Top" Width="77"/>
                        <dxe:TextEdit Name="txtAPostalCode" HorizontalAlignment="Left" Margin="487,131,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95" LostFocus="txtAPostalCode_LostFocus"/>
                        <Button Content="Save" Visibility="Hidden" Name="BtnASave" HorizontalAlignment="Left" Height="30" Margin="330,172,0,0" VerticalAlignment="Top" Width="75" Click="BtnASave_Click"/>
                        <Button Content="Cancel" Name="BtnACancel" HorizontalAlignment="Left" Height="30" Margin="492,172,0,0" VerticalAlignment="Top" Width="75" Click="BtnACancel_Click"/>
                        <Button Content="Update" Visibility="Hidden" x:Name="BtnAEdit" HorizontalAlignment="Left" Height="30" Margin="410,172,0,0" VerticalAlignment="Top" Width="75" Click="BtnAEdit_Click_1"/>
                        <Button Content="Add New" x:Name="BtnAAddNew" HorizontalAlignment="Left" Height="30" Margin="250,172,0,0" VerticalAlignment="Top" Width="75" Click="BtnAAddNew_Click"/>
                        <Label Content="*" x:Name="lblAHonorificError" Foreground="Red" HorizontalAlignment="Left" Margin="227,31,0,0" VerticalAlignment="Top"/>
                        <!--<Label Content="*" x:Name="lblAHonorificError_Copy" Foreground="Red" HorizontalAlignment="Left" Margin="227,57,0,0" VerticalAlignment="Top"/>-->
                        <Label Content="*" x:Name="lblAAddress1Error" Foreground="Red" HorizontalAlignment="Left" Margin="227,84,0,0" VerticalAlignment="Top"/>
                        <Label Content="*" x:Name="lblAAddress2Error" Foreground="Red" HorizontalAlignment="Left" Margin="226,112,0,0" VerticalAlignment="Top"/>
                        <Label Content="*" x:Name="lblACityError" Foreground="Red" HorizontalAlignment="Left" Margin="226,138,0,0" VerticalAlignment="Top"/>
                        <Label Content="*" x:Name="lblAStateError" Foreground="Red" HorizontalAlignment="Left" Margin="384,134,0,0" VerticalAlignment="Top"/>
                        <Label Content="*" x:Name="lblAPostalCodeError" Foreground="Red" HorizontalAlignment="Left" Margin="581,130,0,0" VerticalAlignment="Top"/>
                        <Label Content="*" x:Name="lblAFirstNameError" Foreground="Red" HorizontalAlignment="Left" Margin="370,30,0,0" VerticalAlignment="Top"/>
                        <Label Content="*" x:Name="lblAMiddleNameError" Foreground="Red" HorizontalAlignment="Left" Margin="529,31,0,0" VerticalAlignment="Top"/>
                        <Label Content="*" x:Name="lblALastNameError" Foreground="Red" HorizontalAlignment="Left" Margin="677,29,0,0" VerticalAlignment="Top"/>

                    </Grid>
<Grid Name="grdGroupB" Visibility="Visible" Margin="0,0,141,21" HorizontalAlignment="Right" Width="668">
                        <Label Content="Honorific"  HorizontalAlignment="Left" Margin="18,27,0,0" VerticalAlignment="Top"/>
                        <dxe:TextEdit Name="txtBHonorific" HorizontalAlignment="Left" Margin="134,31,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95"/>
                        <dxe:TextEdit Name="txtBFirstName" HorizontalAlignment="Left" Margin="309,31,0,0" VerticalAlignment="Top" Width="64"/>
                        <Label Content="First Name"  HorizontalAlignment="Left" Margin="242,27,0,0" VerticalAlignment="Top"/>
                        <dxe:TextEdit Name="txtBMiddleName" Margin="0,27,144,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="64"/>
                        <Label Content="Middle Name"  HorizontalAlignment="Left" Margin="378,27,0,0" VerticalAlignment="Top"/>
                        <dxe:TextEdit Name="txtBLastName" HorizontalAlignment="Right" Margin="0,27,10,0" VerticalAlignment="Top" Width="64"/>
                        <Label Content="Last Name" Margin="0,27,73,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="66"/>
                        <Label Content="Company Name"  HorizontalAlignment="Left" Margin="18,53,0,0" VerticalAlignment="Top" Width="100"/>
                        <dxe:TextEdit Name="txtBCompanyName" HorizontalAlignment="Left" Margin="134,58,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95"/>
                        <Label Content="Address1"  HorizontalAlignment="Left" Margin="18,84,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtBAddress1" HorizontalAlignment="Left" Margin="134,85,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95"/>
                        <Label Content="Address2"  HorizontalAlignment="Left" Margin="18,108,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtBAddress2" HorizontalAlignment="Left" Margin="134,112,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95"/>
                        <Label Content="City"  HorizontalAlignment="Left" Margin="18,135,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtBCity" HorizontalAlignment="Left" Margin="134,139,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="95"/>
                        <Label Content="State"  HorizontalAlignment="Left" Margin="250,58,0,0" VerticalAlignment="Top" Width="59"/>
                        <dxe:TextEdit Name="txtBState" HorizontalAlignment="Left" Margin="309,58,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="64"/>
                        <Label Content="Postal Code"  HorizontalAlignment="Left" Margin="378,58,0,0" VerticalAlignment="Top" Width="77"/>
                        <dxe:TextEdit Name="txtBPostalCode" HorizontalAlignment="Left" Margin="460,54,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.091" Width="64"/>
                        <Button Content="Save" Name="BtnBSave" HorizontalAlignment="Left" Height="30" Margin="412,172,0,0" VerticalAlignment="Top" Width="75"/>
                        <Button Content="Cancel" Name="BtnBCancel" HorizontalAlignment="Left" Height="30" Margin="492,172,0,0" VerticalAlignment="Top" Width="75"/>

                    </Grid>

与 Grid 中的所有控件一样。如何根据所选国家/地区设置位置?

帮助赞赏!谢谢!

4

2 回答 2

0

好吧,我不知道现在向您提出以下建议是否为时已晚,但我更喜欢使用不同 VM(每个可能的国家/地区一个)反映地址数据的方法。然后,您可以为每个可选国家创建一个DataTemplate(每个地址 vm 一个)。下一个您需要的是根据传递给它的 VMTemplateSelector选择权利。DataTemplate

这意味着,如果地址 VM 根据 中选择的国家而更改ComboBoxTemplateSelector则将选择相关的DataTemplate。如有必要,通过这种方法,您可以轻松地将您的申请扩展到其他国家/地区。

请注意,此解决方案尊重 MVVM 模式(不确定您是否正在使用它),并且上面的文字只是对我的想法如何实现这种要求的描述。在成功之前,您可能必须解决一些问题。

欲了解更多信息,请点击链接

于 2013-05-21T09:32:17.823 回答
0

这是一个更改两个标签的显示顺序的示例

XAML

<Window x:Class="WpfApplication1.JsonWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="JsonWindow" Height="300" Width="300"
        >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBlock Text="Label 1" Grid.Row="{Binding label1}"/>
        <TextBlock Text="Label 2" Grid.Row="{Binding label2}"/>
        <Button Content="Change Position" Click="Button_Click" Grid.Row="2"/>
    </Grid>
</Window>

代码背后

public partial class JsonWindow : Window, INotifyPropertyChanged {
    public JsonWindow() {
        InitializeComponent();
        this.DataContext = this;
        label1 = 0;
        label2 = 1;
    }

    public int label1 {get;set;}

    public int label2 { get; set; }

    private void Button_Click(object sender, RoutedEventArgs e) {
        label1 = 1;
        label2 = 0;
        PropertyChanged(this, new PropertyChangedEventArgs("label1"));
        PropertyChanged(this, new PropertyChangedEventArgs("label2"));
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

但正如@Novitchi S所说,你将不得不取消你的利润技术。使用 Grid.Row 和 Grid.Column。

于 2013-05-21T09:57:17.127 回答