0

MVVM とカスタム テンプレートを使用して正常に動作しているアカウントのリストを表示する ListView があります。Acct 名をクリックすると、現在の Acct オブジェクトを必要とするカスタム アクションを実行する必要があります。

Label.Tag プロパティを Acct オブジェクトに設定する方法はありますか?

xaml def は env の下にあります vs2010 .net 4.0 c#

<ListView Name="lv1" Grid.Column="1" Grid.Row="4"
    ItemsSource="{Binding AccountsList}"
    Background="Transparent" BorderThickness="0">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image Source="/asm1;component/Images/Icons/pdf1.png" Width="12" Height="12" />
                <Label Content="{Binding Name}" Margin="0,0,25,0" 
                    ContextMenu="{x:Null}" Name="lblacctItem" 
                    MouseDoubleClick="lbl_MouseDoubleClick" />
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Background="Transparent" 
                Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
                ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}" 
                MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}" 
                ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>
4

2 に答える 2

1

MVVM と分離コードを混在させています。

ラベル付けするコマンド動作 ( Link ) を作成する必要があります。次に、CommandParameter を AccObject にバインドし、Command を実行するアクションにバインドする必要があります。

以下は削除する必要があります。

MouseDoubleClick="lbl_MouseDoubleClick"

コメントに従って更新

現在のアイテムは AccObject にバインドされているため、コマンド パラメーターで Binding を使用するだけです。

CommandParameter = {Binding}
于 2012-11-07T06:03:40.007 に答える
1

SelectedItem プロパティをビューモデルの SelectedAccount プロパティに設定できます。

SelectedItem="{Binding SelectedAccount}" Background="Transparent" BorderThickness="0">

SelectedAccount プロパティで INotifyPropertyChanged インターフェイスを使用します。

ありがとう、ラジニカント

于 2012-11-07T06:06:52.747 に答える