在XAML Windows Phone中访问按钮内的图像

本文关键字:按钮 图像 访问 XAML Windows Phone | 更新日期: 2023-09-27 18:06:14

嗨,我是XAML的新手,我需要更改HyperlinkButton内部的图像源,当点击HyperlinkButton时,我正在触发一个事件,请告诉我如何更改图像源

注意: HyperlinkButton已经在ListBox

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

在XAML Windows Phone中访问按钮内的图像

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路径更改为您的新图像。