简体   繁体   English

XAML按钮有问题吗?

[英]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? 尝试使用<Button>完成相同的操作,有什么想法吗?

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. 这是一篇博客文章,其中介绍了更改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... 当然,您也许可以使用Expression潜入HyperlinkBut​​ton的模板(它也可能潜伏在MSDN上的某个地方)并重新使用它...


With a button, I'd do the folowing (using codebehind blech): 使用按钮,即可完成以下操作(使用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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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