开发者

XAML button question?

I have this for a hyperlinkbutton:

<HyperlinkButton x:Name="Home" 
  NavigateUri="/Home" 
  TargetName="ContentFrame" 
  Content="Home" 
  Style="{StaticResource HyperlinkButtonStyl开发者_开发百科e1}">

Trying to accomplish the same using <Button>, any ideas?


Its pretty simple. All you need to do is change the template to make it look the way you want.

Here's a blog post which goes into the details for changing the template for a Button. All you need to do is change the template to something like:

<ControlTemplate TargetType="Button">
  <TextBlock Foreground="Blue">
      <ContentPresenter/>
  </TextBlock>
</ControlTemplate>

Of course, you might be able to sneak out the template for a HyperlinkButton using Expression (it might also be lurking somewhere on MSDN) and reuse it...


With a button, I'd do the folowing (using codebehind blech):

<button Content="Navigate to my page!" Click="Button_Click" />

and in the codebehind:

    void Button_Click(object sender, RoutedEventArgs e)
    {
        // Instantiate the page to navigate to
        var page = new MyPage();

        // Navigate to the page, using the NavigationService
        // this assumes that the event handler is inside of a
        // NavigationWindow
        this.NavigationService.Navigate(page);
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜