locked
Which trigger should be used in ContentControl RRS feed

  • Question

  • Which trigger should be used in ContentControl if i want change some thing when it is pressed or selected. the "Selector.IsSelected" dose not work, and "IsPressed" neither. The XAML code is here:

    <ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
                <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                    <Control Name="RotateDecorator"
                         Template="{StaticResource RotateDecoratorTemplate}"
                         Visibility="Collapsed"/>
                    <s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
                    <Control x:Name="ResizeDecorator"
                         Template="{StaticResource ResizeDecoratorTemplate}"
                         Visibility="Collapsed"/>
                    <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="Selector.IsSelected" Value="True">
                        <Setter TargetName="ResizeDecorator" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="RotateDecorator" Property="Visibility" Value="Visible"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

    Now, I want to know which trigger can work well after instead "Selected.IsSelected"?  Thanks


    ----------definitely maybe
    Thursday, April 1, 2010 3:00 AM

Answers

  • If this question is related to previous questions you posted, I guess (correct me if I'm wrong) you are trying to make the content control "selectable" on the canvas; and when the control is selected, the resize & rotate decorators should become visible so the user can move/resize/rotate the control.

    Is this what you wanted? If not, please elaborate background of the problem like what kind of feature/behavior you want to implement so everyone can better understand your question.

    You might need to create your own control which inherits ContentControl, and add your own IsSelected DP to the control. And then based on how your control can be selected/deselected (for example when mouse down, then the control is selected), set the value of the IsSelected property accordingly.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:10 AM
    Thursday, April 1, 2010 5:50 AM
  • I just mentioned that Canvas is not a Selector because you are trying to use a Trigger Selector.IsSelected property that does not exist in the scope.

    Why don't you just use MouseEnter and GotKeyboardFocus RoutedEvents directly?

     


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:10 AM
    Thursday, April 1, 2010 10:37 AM
  • 1. Yes, I mean EventTrigger RoutedEvent="Canvas.MouseEnter".

    2. If you wan to set IsSelected property to true on mouse down you can set a handler on MyContentControl constructor for that matter. Something like this:

    public MyContetnControl()
    {
       MouseLeftButtonDown += (s, e) => IsSelected = true;
    }

    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:10 AM
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:11 AM
    Saturday, April 3, 2010 3:37 AM

All replies

  • The ContentControl itselft isn't meant to be selected for it holds only one single UIElement as is content, unlike Selector derived controls like ListBox or ComboBox.

    If your ContentControl is child of a Selector derived class you can use Binding expression FindAncestor to get IsSelected property.


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Thursday, April 1, 2010 3:33 AM
  • Now my ContentControl is in a Canvas, and how could i reach my purpose?

    ----------definitely maybe
    Thursday, April 1, 2010 4:29 AM
  • If this question is related to previous questions you posted, I guess (correct me if I'm wrong) you are trying to make the content control "selectable" on the canvas; and when the control is selected, the resize & rotate decorators should become visible so the user can move/resize/rotate the control.

    Is this what you wanted? If not, please elaborate background of the problem like what kind of feature/behavior you want to implement so everyone can better understand your question.

    You might need to create your own control which inherits ContentControl, and add your own IsSelected DP to the control. And then based on how your control can be selected/deselected (for example when mouse down, then the control is selected), set the value of the IsSelected property accordingly.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:10 AM
    Thursday, April 1, 2010 5:50 AM
  • Canvas is not a Selector derived control.

    What do you mean by "Selected", Hyden? Or do you mean "KeyboardFocus" or "MouseOver"?

    Do you have multiple items hosted in ContentControl's using this ControlTemplate?


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Thursday, April 1, 2010 9:44 AM
  • Hi, Bigsby

    I know Canvas is not a Selector, i just used it to explain this case.

    Here my "Selected" means got focus( "MouseEnter" and "KeyboardFocus" ).

    And there will be multiple ContentControls which applied this template in a Canvas


    ----------definitely maybe
    Thursday, April 1, 2010 10:27 AM
  • Yes, Wang. it is what i'm meaning

    I got your idea


    ----------definitely maybe
    Thursday, April 1, 2010 10:32 AM
  • Yes, Wang. it is what i'm meaning

    I got your idea


    ----------definitely maybe
    Thursday, April 1, 2010 10:32 AM
  • I just mentioned that Canvas is not a Selector because you are trying to use a Trigger Selector.IsSelected property that does not exist in the scope.

    Why don't you just use MouseEnter and GotKeyboardFocus RoutedEvents directly?

     


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:10 AM
    Thursday, April 1, 2010 10:37 AM
  • Sorry, i'm not familiar with this.

    Do you mean add a EventTrigger in the template or add a RoutedEvent "MouseEnter" in the canvas?


    ----------definitely maybe
    Friday, April 2, 2010 2:18 AM
  • Hi, Wang Jie

    I'm trying to add a dependency property "IsSelected". I know how to regist it, while don't know how to change it when the mouse down action happens

    class MyContentControl:ContentControl
        {
            public static readonly DependencyProperty IsSlectedProperty = DependencyProperty.Register("IsSlectedProperty", typeof(bool), typeof(MyContentControl), new FrameworkPropertyMetadata(false,new ));
            public bool IsSlected
            {
                get { return (bool)GetValue(IsSlectedProperty); }
                set { SetValue(IsSlectedProperty, value); }
            }
        }


    ----------Definitely, Maybe
    Friday, April 2, 2010 7:40 AM
  • 1. Yes, I mean EventTrigger RoutedEvent="Canvas.MouseEnter".

    2. If you wan to set IsSelected property to true on mouse down you can set a handler on MyContentControl constructor for that matter. Something like this:

    public MyContetnControl()
    {
       MouseLeftButtonDown += (s, e) => IsSelected = true;
    }

    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:10 AM
    • Marked as answer by Hyden Huang Wednesday, April 7, 2010 6:11 AM
    Saturday, April 3, 2010 3:37 AM