使用自定义按钮样式更改按钮内容前景或笔触颜色

时间:2016-05-21 05:57:41

标签: xaml win-universal-app uwp windows-10-universal

我尝试使用像这样的自定义按钮样式更改鼠标悬停时按钮内容的椭圆的描边:

<Button x:Name="MyButton" Style="{StaticResource MyButtonStyle}">
    <StackPanel>
                <Ellipse Width="20" Height="20" Stroke="{x:Bind MyButton.Foreground, Mode=OneWay}"></Ellipse>
                <TextBlock Foreground="{x:Bind MyButton.Foreground, Mode=OneWay}" Text="Not Working" />
                <TextBlock Text="Working" />
    </StackPanel>
</Button>

为什么只有TextBlock与Text&#34; Working&#34;改变它的前景属性?

var tbody = $('#tbody'),        
    htmlStr = "";

for (var i = 0, len = articlelist.length; i < len; i++) {  // avoid accessing 'length' property on each iteration
     htmlStr += '<tr><td>' + articlelist[i].id + '</td>'
                + '<td>' + articlelist[i].channelid + '</td>'
                + '<td>' + articlelist[i].comment + '</td>'
                + '<td>' + articlelist[i].last_edit_time + '</td><td><tr>';        
}
tbody.append(htmlStr); // parses the specified text as HTML or XML and inserts the resulting nodes

1 个答案:

答案 0 :(得分:1)

  1. 您的视觉状态动画正在修改ContentPresenter的前景而不是ButtonMyButton)的前景。
  2. 使用ContentControl代替ContentPresenter以访问模板中的其他属性。
  3. 访问其他控件的Foreground,例如以下内容。
  4. 代码:

    <StackPanel>
         <Ellipse Width="20" Height="20" Stroke="{x:Bind MyText.Foreground, Mode=OneWay}"></Ellipse>
         <TextBlock Foreground="{x:Bind MyText.Foreground, Mode=OneWay}" Text="Not Working" />
         <TextBlock x:Name="MyText" Text="Working" />
    </StackPanel>