我有一个ComboEdit,其中显示了国家/地区列表。在表单上,它们是一个ADDRESS选项卡,在选择ComboEdit值时设置为激活。控件在ADDRESS选项卡上的位置必须根据指定的布局进行更改(我们可以在此使用Databsase根据所选国家/地区存储布局)。
我想显示地址格式&根据comboedit选择的公司指定的每个订单的动态控制。请参阅不同的地址格式: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中的所有控件。如何根据所选国家设定位置?
帮助感谢! 谢谢!
答案 0 :(得分:0)
嗯,我不知道为你提供以下建议是否为时已晚,但我更倾向于使用不同的虚拟机(每个可能的国家一个)来反映地址数据。然后,您可以为每个可选国家/地区创建DataTemplate
(每个地址vm一个)。您需要的下一个是TemplateSelector
,根据传递给它的VM选择正确的DataTemplate
。
这意味着,如果根据ComboBox
中所选国家/地区更改了地址VM,则TemplateSelector
会选择相关的DataTemplate
。通过这种方法,您可以根据需要轻松扩展其他国家/地区的应用程序。
请注意,此解决方案尊重MVVM模式(不确定您是否正在使用它),并且上面的文字只是我对如何实现此类要求的想法的描述。在成功之前,您可能必须解决一些问题。
欲了解更多信息,请点击链接
答案 1 :(得分: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。