views:

28

answers:

2

Hello,
We use System.Windows.Shapes.Path to visually connect elements in our application.
Is it possible to 'select' the Path object and give it focus? We want to allow our users to change some style elements of any Path object.

In our LeftMouseButtonDown handler, we detect that we have clicked on a Path object, but then what? I hook up a GotFocus handler to the Path object, but it never gets called.

I suspect I need a container around the Path object....
Thanks for any insight.

A: 

You probably want to create a custom control that wraps around a Path element. The path is a very basic graphics primitive and does not have the notion of "focus" or "state" the way a Control does.

KeithMahoney
Thanks, that's what I suspected....
Number8
A: 

If you are using blend, you can right click on the path in the objects and timeline section and "make into control"
Choose something simple like a radio button and you can add storyboards to the visual states for focused or checked, etc.
The code that it creates for your path will be something like the following, if you don't have blend.

 <Style x:Key="RadioButtonStyle1" TargetType="RadioButton">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="RadioButton">
        <Grid>
          <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
              <VisualState x:Name="Pressed"/>
              <VisualState x:Name="Normal"/>
              <VisualState x:Name="MouseOver"/>
              <VisualState x:Name="Disabled"/>
            </VisualStateGroup>
              <VisualStateGroup x:Name="FocusStates">
              <VisualState x:Name="Focused"/>
              <VisualState x:Name="Unfocused"/>
            </VisualStateGroup>
            <VisualStateGroup x:Name="ValidationStates">
              <VisualState x:Name="Valid"/>
              <VisualState x:Name="InvalidFocused"/>
              <VisualState x:Name="InvalidUnfocused"/>
            </VisualStateGroup>
            <VisualStateGroup x:Name="CheckStates">
              <VisualState x:Name="Unchecked"/>
              <VisualState x:Name="Checked"/>
            <VisualState x:Name="Indeterminate"/>
            </VisualStateGroup>
          </VisualStateManager.VisualStateGroups>
          <Path />
      </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>
RCGoforth

related questions