0

では、みなさんこんにちは。

独自のコントロールを作成するための 2 つのテスト プログラムを作成しました。Silverlight に 1 つ、WPF に 1 つ。一種の RangeSlider を作成しました。このスライダーにはもちろん、水平方向と垂直方向の 2 つの方向があります。最初に、RangeSlider を作成するために 2 つの異なる手法を使用しました。WPF ではトリガーを使用し、Silverlight では (トリガーがないことを知っています)、CodeBehind.This の水平および垂直テンプレートの可視性を変更しました。

現在: Silverlight と WPF の両方に 1 つの手法を使用しようとしています。したがって、VisualStateManager を使用します。

2 つのスライダー (1 つは左の値用、もう 1 つは右の値用) を定義するテンプレートがあります。重要な値を単純化すると、次のようになります。

...
<ControlTemplate>
  <Grid x:Name="PART_Content">
    <!-- VSM: See following code sequence -->
    <Grid x:Name="PART_HorizontalTemplate">
      <Slider x:Name="PART_HorizontalSliderLeft"
              Template="{StaticResource HorizontalSliderTemplate}"
              Orientation="{TemplateBinding Orientation}" />
      ...
    </Grid>
    <Grid x:Name="PART_VerticalTemplate">
      ...
    </Grid>
  </Grid>
</ControlTemplate>

さらに、水平方向と垂直方向の外観を切り替える VSM があります。

<VisualStateManager.VisualStateGroups>
  <VisualStateGroup>
    <VisualState x:Name="Vertical">
      <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HorizontalTemplate"
                                       Storyboard.TargetProperty="Visibility">
          <DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0"/>
        </ObjectAnimationUsingKeyFrames>
      </Storyboard>
    </VisualState>
    <VisualState x:Name="Horizontal" />
  </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

これはまだ実行されます。

コード シーケンスでわかるように、Slider のビジュアルは Template によって定義されます。

<ControlTemplate x:Key="HorizontalSliderTemplate" TargetType="{x:Type Slider}">
  <Border x:Name="Border" ...>
    <!-- VSM here. Like above. -->
    <Grid x:Name="Grid">
      <Rectangle x:Name="PART_SelectionRange"/>
      <Track x:Name="PART_Track">
        ...
      </Track>
    </Grid>
  </Border>
</ControlTemplate>

実は VerticalSliderTemplate もあります。しかし、両方の ControlTemplate を 1 つの Template に結合し、VSM を使用したいと考えています。ここで私の問題に行きます:

「内側」の ControlTemplate で VSM を実行できません。これは、実行中の VSM-Part とほぼ同じコードで、TargetName が変更されているだけです。GoToState で実行されているものをデバッグする方法はわかりませんが、テンプレート内の VSM が見つからず、そこから実行されることはないと思います。

細部が少し欠けているだけだと想像できますが、「木を見て木が見えない」のです。テンプレートや VSM について私が知らない重要なことがあり、軌道から外れているのかもしれません。または、外部から「内部」VSM をトリガーする必要がありますか、または「外部 VSM」から要素にアクセスする可能性がありますか? または、「内部」テンプレートの VSM にアクセスできませんか?

私の問題を十分に説明できることを願っています。誰かが解決策を知っているか、私が探すことができるキーワードを知っています。Google で VSM、ControlTemplate、Storyboard などのキーワードを入力するだけでは何の助けにもなりません。

前もって感謝します。

4

2 に答える 2

0

それで、私はそれについて解決策を得ました。要素に追加した「内部」テンプレートで、DataTrigger を切り替えます。この DataTrigger は PART_Horizo​​ntalTemplate Visibility にバインドされており、必要なアクションを実行する Storyboard が含まれています。

コードが大幅に拡張され、より複雑に見えるため、実際には私が探していた種類のソリューションではない可能性があります。しかし、それが最も重要なことですが、うまく動作します。

于 2011-06-03T09:45:17.683 に答える
0

1 つの ControlTemplate 内に複数の VSM を持つことはできないと思います。

1 つの VSM を使用して両方を切り替えてみませんか。

<ControlTemplate>
  <Grid x:Name="PART_Content">
    <Grid x:Name="PART_HorizontalTemplate">
      ...
    </Grid>
    <Grid x:Name="PART_VerticalTemplate">
      ...
    </Grid>
<VisualStateManager.VisualStateGroups>
  <VisualStateGroup>
    <VisualState x:Name="Vertical">
      <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HorizontalTemplate"
                                       Storyboard.TargetProperty="Visibility">
          <DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0"/>
        </ObjectAnimationUsingKeyFrames>
      </Storyboard>
    </VisualState>
    <VisualState x:Name="Horizontal">
<Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_VerticalTemplate"
                                       Storyboard.TargetProperty="Visibility">
          <DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0"/>
        </ObjectAnimationUsingKeyFrames>
      </Storyboard>
    </VisualState>
  </VisualStateGroup>
</VisualStateManager.VisualStateGroups>
  </Grid>
</ControlTemplate>
于 2011-06-01T15:15:57.983 に答える