使用DevExpress和dataBinding的IdialogService

时间:2014-10-03 12:49:49

标签: c# wpf mvvm data-binding devexpress

我在mvvm模式设计中工作。 过了一会儿,我可以随意使用devExpress dialogService。

我必须从我的mainWindowViewModel绑定两个数据:一个用于填充组合框和一个对象的集合,绑定到布局控件(此对话框用于插入新项目)。

在我的usercontrol的头部,在对话框中显示,我有:

DataContext="{dxmvvm:ViewModelSource vm:MainWindowViewModel}"

通过这种方式正确绑定集合:                   

虽然不起作用的绑定是:

<dxlc:LayoutControl Grid.Column="1" Orientation="Vertical" UseLayoutRounding="True" Margin="0,10,0,0"
        DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl},
        Path=DataContext.impiantoVuoto, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

layoutControl只是绑定到一个空对象。当我编写新字段并单击&#34; ok&#34;时,由于绑定,它必须保存这些数据。但这不起作用,当我去mainViewModel时,空对象仍然是空的。为什么呢?

这是我的整个用户控件:

<UserControl x:Class="MyNS.View.Generic.nuovoImpianto"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:MyNS"
             xmlns:vm="clr-namespace:MyNS.ViewModel"
             xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             xmlns:View="clr-namespace:MyNS.View"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxprg="http://schemas.devexpress.com/winfx/2008/xaml/propertygrid"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:sys="clr-namespace:System;assembly=mscorlib" 
             xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" 
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             DataContext="{dxmvvm:ViewModelSource vm:MainWindowViewModel}"
             >
    <UserControl.Resources>
        <vm:InverseBooleanConverter x:Key="InverseBooleanConverter" />

    </UserControl.Resources>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <dxlc:LayoutControl Grid.Column="1" Orientation="Vertical" UseLayoutRounding="True" Margin="0,10,0,0"
                            DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl},
                                          Path=DataContext.impiantoVuoto, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            <dxlc:LayoutGroup Header="Info generali" View="GroupBox" Orientation="Vertical" >
                <dxlc:LayoutItem Label="Codice">
                    <dxe:TextEdit EditValue="{Binding CODICE}" />
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="Nome">
                    <dxe:TextEdit EditValue="{Binding NOME}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="Città">
                    <dxe:TextEdit EditValue="{Binding LOCALITA}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="Indirizzo">
                    <dxe:TextEdit EditValue="{Binding INDIRIZZO}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="CAP">
                    <dxe:TextEdit EditValue="{Binding CAP}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="P. IVA">
                    <dxe:TextEdit EditValue="{Binding PIVA}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="Telefono">
                    <dxe:TextEdit EditValue="{Binding TELEFONO}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="Responsabile">
                    <dxe:TextEdit EditValue="{Binding RESPONSABILE}"/>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="E-mail">
                    <dxe:TextEdit EditValue="{Binding EMAILS}"/>
                </dxlc:LayoutItem>
            </dxlc:LayoutGroup>

            <dxlc:LayoutGroup Header="Configurazione tecnica" View="GroupBox" Orientation="Vertical">
                <dxlc:LayoutItem Label="Tipo sistema">
                    <dxe:ComboBoxEdit IsTextEditable="False" EditValue="{Binding IDTTS}" 
                                      ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl},Path=DataContext.tts}"  />
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="Locazione">
                    <StackPanel Margin="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left">
                        <RadioButton Content="{DynamicResource Locale}" Margin="10,0,0,0" x:Name="rd_LOCALE" VerticalAlignment="Center"  
                                          GroupName="LocationL" Panel.ZIndex="9" TabIndex="10" />
                        <RadioButton Content="{DynamicResource Remoto}" Margin="10,0,6,0" x:Name="rd_REMOTO" VerticalAlignment="Center" 
                                         IsChecked="{Binding REMOTO}" GroupName="LocationR" Panel.ZIndex="10" TabIndex="11" Tag="PRISMA"/>
                    </StackPanel>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem Label="Tipo di connessione">
                    <StackPanel Margin="0" Orientation="Horizontal" VerticalAlignment="Center">
                        <RadioButton x:Name="rd_TIPOCONN" Content="{DynamicResource Terminale}" Margin="10,0,0,0" Tag="PRISMA" VerticalAlignment="Center" GroupName="TipoConnT" 
                                          Panel.ZIndex="11" TabIndex="12" />
                        <RadioButton x:Name="rd_SLAVE" Content="Slave" Margin="10,0,6,0" Tag="PRISMA" VerticalAlignment="Center" GroupName="TipoConnS" 
                                         IsChecked="{Binding TIPOCONN}" Panel.ZIndex="12" TabIndex="13" />
                    </StackPanel>
                </dxlc:LayoutItem>
            </dxlc:LayoutGroup>

            <dxlc:LayoutGroup Header="Centralina STK" View="GroupBox" Orientation="Vertical">
                <dxlc:LayoutItem >
                    <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,6">
                        <RadioButton x:Name="rd_sermatic" Content="{DynamicResource SI}" Margin="10,0,0,0"  Tag="PRISMA" VerticalAlignment="Center" Width="100" 
                                         HorizontalAlignment="Left" IsChecked="{Binding SERMATIC}" GroupName="stkS" Panel.ZIndex="13" TabIndex="14" />
                        <RadioButton x:Name="rd_sermaticNO" Content="{DynamicResource NO}" Margin="10,0,0,0" Tag="PRISMA" VerticalAlignment="Center" Width="100" 
                                         HorizontalAlignment="Left"  GroupName="stkN" 
                                         Panel.ZIndex="14" TabIndex="15" />
                    </StackPanel>
                </dxlc:LayoutItem>
                <dxlc:LayoutItem >
                    <!--<dxe:ComboBoxEdit  EditValue="{Binding SERMATICCOM}"/>-->
                    <UniformGrid Rows="1" Columns="2" DockPanel.Dock="Top" Margin="4,0,4,4" IsEnabled="{Binding IsChecked, ElementName=rd_sermatic}">
                        <TextBlock Margin="0" TextWrapping="Wrap" Text="{DynamicResource PortaCOM}" TextAlignment="Right" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                        <ComboBox x:Name="cmb_SERMATICCOM" Height="23" Margin="10,2,0,0" Panel.ZIndex="15" TabIndex="16">
                            <ComboBoxItem Content="COM1" />
                            <ComboBoxItem Content="COM2" />
                            <ComboBoxItem Content="COM3" />
                            <ComboBoxItem Content="COM4" />
                            <ComboBoxItem Content="COM5" />
                            <ComboBoxItem Content="COM6" />
                            <ComboBoxItem Content="COM7" />
                            <ComboBoxItem Content="COM8" />
                        </ComboBox>
                    </UniformGrid>
                </dxlc:LayoutItem>
            </dxlc:LayoutGroup>
        </dxlc:LayoutControl>
    </StackPanel>
</UserControl>

我的错误在哪里?

0 个答案:

没有答案