【问题标题】:Access Image inside the Button in XAML Windows Phone在 XAML Windows Phone 中访问按钮内的图像
【发布时间】:2014-06-07 05:42:13
【问题描述】:

您好,我是 XAML 的新手,我需要在单击 HyerLinkBut​​ton 时更改 HyperlinkBut​​ton 内的图像源,我正在触发一个事件,请告诉我如何更改图像源

注意:超链接按钮已经在列表框中

XAML

    <HyperlinkButton x:Name="SaveData" Width="Auto" CommandParameter="{Binding business_id}" Click="SaveData_Click">
                                        <HyperlinkButton.Template>
                                            <ControlTemplate>
                                                <Image Source="/Assets/Images/MainPageImg/save.png" Width="50" HorizontalAlignment="Right" Margin="0,0,15,0"></Image>
                                            </ControlTemplate>
                                        </HyperlinkButton.Template>
                                    </HyperlinkButton>

C# 代码

 private void SaveData_Click(object sender, RoutedEventArgs e)
    {
        HyperlinkButton HyperlinkButton = (HyperlinkButton)sender;
        string value = HyperlinkButton.CommandParameter.ToString();
        saveevt = true;
        using (var db = new SQLiteConnection(dbPath))
        {
            db.RunInTransaction(() =>
            {
                db.Insert(new Travel() { id = value });
            });
        }
    }

【问题讨论】:

  • 尝试为图像赋予Namex:Key 属性。
  • 如果您用Image 覆盖HyperlinkButton 的模板,为什么不直接使用Image 并监听Tap 事件?

标签: c# xaml windows-phone


【解决方案1】:
private void SaveData_Click(object sender, RoutedEventArgs e) {

BitmapImage imgSource = new BitmapImage(
      new Uri("/Assests/Images/MainpageImg/save.png", UriKind.Relative));
image1.Source = null;
image1.Source = imgSource;

}

将图像的 Uri 路径更改为您的新图像。 希望这对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多