티스토리 뷰
Behavior SDK를 이용해서 작업을 하다보니 ItemClick 이벤트에 대한 처리를 할 수 없다는 걸 알았다.
그래서 InvokeActionCommandEx라는 IAction 클래스를 만들어 보았다.
InvokeActionCommand를 CommandParameter를 사용하지 않으면 기본적으로 이벤트 아규먼트를 반환한다.
즉, 아래의 내용은 참고로만 사용하도록 한다.
public class InvokeActionCommandEx : DependencyObject, Microsoft.Xaml.Interactivity.IAction
{
#region Static Fields
/// <summary>
/// Defines the CommandParameter dependency property, of type <see cref="object"/>.
/// </summary>
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
"CommandParameter",
typeof(object),
typeof(InvokeActionCommandEx),
new PropertyMetadata(null));
/// <summary>
/// Defines the Command dependency property, of type <see cref="ICommand"/>.
/// </summary>
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
"Command",
typeof(ICommand),
typeof(InvokeActionCommandEx),
new PropertyMetadata(null));
/// <summary>
/// Defines the Command dependency property, of type <see cref="PassEventArgsToCommand"/>.
/// </summary>
public static readonly DependencyProperty PassEventArgsToCommandProperty = DependencyProperty.Register(
"PassEventArgsToCommand",
typeof(bool),
typeof(InvokeActionCommandEx),
new PropertyMetadata(false));
#endregion
#region Public Properties
/// <summary>
/// Gets or sets the command to be invoked.
/// </summary>
public ICommand Command
{
get
{
return (ICommand)this.GetValue(CommandProperty);
}
set
{
this.SetValue(CommandProperty, value);
}
}
/// <summary>
/// Gets or sets the command parameter to pass to the <see cref="ICommand"/> upon invocation.
/// </summary>
/// <remarks>
/// This takes precedence over the <see cref="PassEventArgsToCommand"/> property - if <see cref="CommandParameter"/>
/// is specified, then <see cref="PassEventArgsToCommand"/> is ignored.
/// </remarks>
public object CommandParameter
{
get
{
return this.GetValue(CommandParameterProperty);
}
set
{
this.SetValue(CommandParameterProperty, value);
}
}
/// <summary>
/// Gets or sets a value indicating whether or not the event arguments associated to the raised
/// event should be passed to the command.
/// </summary>
public bool PassEventArgsToCommand
{
get
{
return (bool)this.GetValue(PassEventArgsToCommandProperty);
}
set
{
this.SetValue(PassEventArgsToCommandProperty, value);
}
}
#endregion
public object Execute(object sender, object parameter)
{
FrameworkElement element = sender as FrameworkElement;
if (element != null && Command != null && Command.CanExecute(CommandParameter))
{
Command.Execute(CommandParameter == null && PassEventArgsToCommand == true ? parameter : this.CommandParameter);
}
return null;
}
}
XAML에서 사용
xmlns:t="using:Microsoft.Xaml.Interactivity"
xmlns:i="using:KTour.Behaviors" //본인이 만든위치의 네임스페이스를 사용하면 된다.
<ListView Margin="0,0,0,10" Grid.Column="1" ItemsSource="{Binding SiGunGu}"
ItemTemplate="{StaticResource SiGunGuItemTemplate}"
IsItemClickEnabled="True" SelectedItem="{Binding SelectedSiGunGu, Mode=TwoWay}" Style="{StaticResource RemoveScrollViewerListViewStyle}"
BorderBrush="{StaticResource PageBackgroundBrush}" BorderThickness="1" ItemContainerStyle="{StaticResource ListViewItemContainerStyle}">
<t:Interaction.Behaviors>
<c:EventTriggerBehavior EventName="ItemClick">
<i:InvokeActionCommandEx Command="{Binding SiGunGuClickCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
</c:EventTriggerBehavior>
</t:Interaction.Behaviors>
</ListView>
ListView, GridView에서 ItemClick이벤트를 사용하는 경우 위와 같이 사용한다.
'Previous Platforms' 카테고리의 다른 글
Nokia Lumia 925 Get! (0) | 2013.12.03 |
---|---|
Windows Store languages country list (0) | 2013.11.26 |
Behaviors SDK (0) | 2013.11.20 |
Windows 8 App Award (0) | 2013.11.19 |
Korea Tour 개발 후기 (0) | 2013.10.11 |
- Total
- Today
- Yesterday
- LINQ
- kiosk
- .net
- visual studio 2019
- Windows 10
- Microsoft
- .net 5.0
- uno platform
- IOT
- Bot Framework
- dotNETconf
- MVVM
- XAML
- UWP
- #Windows Template Studio
- windows 11
- ef core
- uno-platform
- Cross-platform
- Build 2016
- Behavior
- Always Encrypted
- C#
- #uwp
- #prism
- ComboBox
- #MVVM
- WPF
- PRISM
- Visual Studio 2022
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |