CommandParameter binding Introduction:

<Window x:Class="OddEvenRows.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        Height="400" Width="300"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" Title="JackSlater" x:Name="jackWindow">
    <Window.Resources>
        <FrameworkElement x:Key="ProxyElement" DataContext="{Binding Path=.,ElementName=noTB01}"/>
    </Window.Resources>
    <StackPanel>
        <ContentControl Visibility="Collapsed" Content="{StaticResource ProxyElement}"/>
        <StackPanel>
            <TextBlock x:Name="noTB01" Text="No.1"></TextBlock>
            <TextBlock x:Name="noTB02" Text="No.2"></TextBlock>
            <Button x:Name="testBtn" Content="Hello"></Button>
        </StackPanel>
        <Grid>
            <dxg:GridControl x:Name="gridControl" Grid.Row="2" MaxHeight="500" ItemsSource="{Binding MyList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                <dxg:GridControl.Columns>
                    <dxg:GridColumn FieldName="Index">
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <dxe:ComboBoxEdit Name="PART_Editor" IsTextEditable="False" >
                                    <dxe:ComboBoxEditItem x:Name="readyCombox" Content="ClickDownComboxItem">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="PreviewMouseDown">
                                                <cmd:EventToCommand
                                             Command="{Binding Path=View.DataContext.ImportCommand}"
                                             CommandParameter="{Binding Path=DataContext.Text, Source={StaticResource ProxyElement}}"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </dxe:ComboBoxEditItem>
                                </dxe:ComboBoxEdit>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                    <dxg:TableView AutoWidth="True"/>
                </dxg:GridControl.View>
            </dxg:GridControl>
        </Grid>
    </StackPanel>
</Window>
<Window x:Class="OddEvenRows.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        Height="400" Width="300"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" Title="JackSlater" x:Name="jackWindow">
    <dxg:GridControl x:Name="gridControl"  ItemsSource="{Binding MyList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                <dxg:GridControl.Columns>
                    <dxg:GridColumn FieldName="Index">
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <dxe:ComboBoxEdit EditValue="{Binding Data.Index,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" IsTextEditable="False" >
                                    <dxe:ComboBoxEditItem x:Name="readyCombox" Content="ClickDownComboxItem">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="PreviewMouseDown">
                                                <cmd:EventToCommand
                                             Command="{Binding Path=View.DataContext.ImportCommand}"
                                             CommandParameter="{Binding Path=View.DataControl.Parent}"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </dxe:ComboBoxEditItem>
                                </dxe:ComboBoxEdit>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                    <dxg:TableView AutoWidth="True"/>
                </dxg:GridControl.View>
            </dxg:GridControl>
</Window>
<Window x:Class="OddEvenRows.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        Height="400" Width="300"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" Title="JackSlater" x:Name="jackWindow">
    <Window.Resources>
        <!--<FrameworkElement x:Key="ProxyElement" DataContext="{Binding noTB01}"/>-->
        <TextBlock x:Key="ProxyElement" DataContext="{Binding Path=.,ElementName=noTB01}"/>
    </Window.Resources>
    <StackPanel>
        <ContentControl Visibility="Collapsed" Content="{StaticResource ProxyElement}"/>
        <StackPanel>
            <TextBlock x:Name="noTB01" Text="No.1"></TextBlock>
            <TextBlock x:Name="noTB02" Text="No.2"></TextBlock>
            <Button x:Name="testBtn" Content="Hello"></Button>
        </StackPanel>
        <Grid>
            <dxg:GridControl x:Name="gridControl" Grid.Row="2" MaxHeight="500" ItemsSource="{Binding MyList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                <dxg:GridControl.Columns>
                    <dxg:GridColumn FieldName="Index">
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <dxe:ComboBoxEdit Name="PART_Editor" IsTextEditable="False" >
                                    <dxe:ComboBoxEditItem x:Name="readyCombox" Content="ClickDownComboxItem">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="PreviewMouseDown">
                                                <cmd:EventToCommand
                                             Command="{Binding Path=View.DataContext.ImportCommand}"
                                             CommandParameter="{Binding Path=DataContext.Text,Source={StaticResource ProxyElement}}"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </dxe:ComboBoxEditItem>
                                </dxe:ComboBoxEdit>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                    <dxg:TableView AutoWidth="True"/>
                </dxg:GridControl.View>
            </dxg:GridControl>
        </Grid>
    </StackPanel>
</Window>

http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/

http://stackoverflow.com/questions/7660967/wpf-error-cannot-find-govering-frameworkelement-for-target-element

http://stackoverflow.com/questions/7660967/wpf-error-cannot-find-govering-frameworkelement-for-target-element

DevExpressCenter:

http://www.devexpress.com/Support/Center/Question/Details/T129527

CommandParameter binding Introduction:,布布扣,bubuko.com

时间: 2024-10-06 01:19:23

CommandParameter binding Introduction:的相关文章

[WPF]解决模板中ContextMenu绑定CommandParameter的问题

直接上代码,首先是一个ContextMenu的模板: <ContextMenu x:Key="Menu" BorderThickness="0.3" FontSize="13" DataContext="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"> <MenuItem Header="复制" Co

背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令

原文:背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 [源码下载] 作者:webabcd 介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 示例1.ModelMVVM/Model/Product.cs /* * Model 层的实

WPF - MVVM - 如何将ComboBox的Selectchange事件binding到ViewModel

将所有的事件,属性,都映射到ViewModel中.好处多多,以后开发尽量用这种模式. 解决方法: 使用System.Windows.Interactivity.dll,添加该dll到项目引用 ? 1 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" ComboBox映射的代码: <ComboBox VerticalAlignment="Ce

MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令

介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 示例1.ModelMVVM/Model/Product.cs /* * Model 层的实体类,如果需要通知则需要实现 INotifyPropertyChanged 接口 */ using System.ComponentModel; namespace Windows10.MVVM.Model

MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令

介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 示例1.ModelMVVM/Model/Product.cs /* * Model 层的实体类,如果需要通知则需要实现 INotifyPropertyChanged 接口 */ using System.ComponentModel; namespace Windows10.MVVM.Model {

WPF TreeGrid Binding 简易实现方式

在設計TreeView編輯狀況下,希望 TreeItemName 后续的编辑框 复选框 可以整齐排列. 参考微软提供的TREELISTVIEW,发现它是根据层级关系调整Margin 属性. 我这边按照同样的方式,实现WIDTH的宽度的递减,就可实现需要的效果. <HierarchicalDataTemplate x:Key="TreeNodes" ItemsSource="{Binding Path=Childs,Mode=TwoWay}" > <

背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令

[源码下载] 作者:webabcd 介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 示例1.ModelMVVM/Model/Product.cs /* * Model 层的实体类,如果需要通知则需要实现 INotifyPropertyChanged 接口 */ using System.ComponentModel; namespace Wind

TreeView 中 MVVM Command Binding

<HierarchicalDataTemplate x:Key="TreeNodes" ItemsSource="{Binding Path=Childs,Mode=OneWay}" > <StackPanel Orientation="Horizontal" Height="24" DataContext="{Binding}"> <TextBlock Text="

WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参

原文:WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参 ContextMenu无论定义在.cs或.xaml文件中,都不继承父级的DataContext,所以如果要绑定父级的DataContext,直接DataContext=“{Binding}”是行不通的 不能绑父级,但是能绑资源 第一步:定义一个中间类用来做资源对象 1 public class BindingProxy : Freezable 2 { 3 #region Over