开发者

Silverlight custom control's content in scrollviewer

开发者 https://www.devze.com 2022-12-09 17:26 出处:网络
I have a Silverlight control derived from ContentControl. I use it in following way <local:CustomControl>

I have a Silverlight control derived from ContentControl. I use it in following way

<local:CustomControl>
 <local:AnotherControl>
</local:CustomControl>

I want to have the content (i.e. AnotherControl开发者_JAVA百科) in a ScrollViewer. Without changing the above XAML usage, how can I have the content in scrollviewer? What modification do I need to make in CustomControl's template?

Thanks


I found the way to do this I defined control template as following

<Style TargetType="local:MyCustomControl">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:MyCustomControl">
        <ScrollViewer>
          <Canvas>
           <ContentPresenter/>
          </Canvas>
        </ScrollViewer>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

Its working for me. Is it the proper way?

0

精彩评论

暂无评论...
验证码 换一张
取 消