0
이 두 방법은 어디에도 호출되지 않습니다. 그들이 부착 된 행동을 사용하기 위해 필요합니까 아니면 재산을 얻기위한 편리한 편의성입니까? http://www.codeproject.com/Articles/28959/Introduction-to-Attached-Behaviors-in-WPFWPF 첨부 된 동작을 정의 할 때 이러한 메서드가 필요한 이유는 무엇입니까?
public static class TreeViewItemBehavior
{
#region IsBroughtIntoViewWhenSelected
public static bool GetIsBroughtIntoViewWhenSelected(TreeViewItem treeViewItem)
{
return (bool)treeViewItem.GetValue(IsBroughtIntoViewWhenSelectedProperty);
}
public static void SetIsBroughtIntoViewWhenSelected(
TreeViewItem treeViewItem, bool value)
{
treeViewItem.SetValue(IsBroughtIntoViewWhenSelectedProperty, value);
}
public static readonly DependencyProperty IsBroughtIntoViewWhenSelectedProperty =
DependencyProperty.RegisterAttached(
"IsBroughtIntoViewWhenSelected",
typeof(bool),
typeof(TreeViewItemBehavior),
new UIPropertyMetadata(false, OnIsBroughtIntoViewWhenSelectedChanged));
static void OnIsBroughtIntoViewWhenSelectedChanged(
DependencyObject depObj, DependencyPropertyChangedEventArgs e)
{
TreeViewItem item = depObj as TreeViewItem;
if (item == null)
return;
if (e.NewValue is bool == false)
return;
if ((bool)e.NewValue)
item.Selected += OnTreeViewItemSelected;
else
item.Selected -= OnTreeViewItemSelected;
}
static void OnTreeViewItemSelected(object sender, RoutedEventArgs e)
{
// Only react to the Selected event raised by the TreeViewItem
// whose IsSelected property was modified. Ignore all ancestors
// who are merely reporting that a descendant's Selected fired.
if (!Object.ReferenceEquals(sender, e.OriginalSource))
return;
TreeViewItem item = e.OriginalSource as TreeViewItem;
if (item != null)
item.BringIntoView();
}
#endregion // IsBroughtIntoViewWhenSelected
아니요; 그들은 필요하지 않습니다. – SLaks
+1에 대한 SLaks. IsBroughtIntoViewWhenSelected는 아마도 xaml 어딘가에 설정되어있을 것입니다. 이 두 가지 get 및 set 메소드는 실제로 필요하지 않습니다. 코드를 수동으로 읽거나 값을 설정하려는 경우에만 도우미입니다. –
@SLaks,이 질문을 수락 된 것으로 표시 할 수 있도록 답변에서 다소 의견을 넓혀 주실 수 있습니까? – Sheridan