简体   繁体   中英

XAML button question?

I have this for a hyperlinkbutton:

<HyperlinkButton x:Name="Home" 
  NavigateUri="/Home" 
  TargetName="ContentFrame" 
  Content="Home" 
  Style="{StaticResource HyperlinkButtonStyle1}">

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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM