簡體   English   中英

XAML按鈕有問題嗎?

[英]XAML button question?

我有一個超鏈接按鈕:

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

嘗試使用<Button>完成相同的操作,有什么想法嗎?

非常簡單。 您需要做的就是更改模板,使其看起來像您想要的樣子。

這是一篇博客文章,其中介紹了更改Button模板的詳細信息。 您需要做的就是將模板更改為以下內容:

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

當然,您也許可以使用Expression潛入HyperlinkBut​​ton的模板(它也可能潛伏在MSDN上的某個地方)並重新使用它...


使用按鈕,即可完成以下操作(使用blech背后的代碼):

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

並在后面的代碼中:

    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