我的问题是,当我从OpenFileDialog
上传我的图片时,个人资料图片不会更新。
我认为我的问题是我需要INotifyPropertyChanged
,但我不知道如何使用我的代码。
这是我的代码:
private void ProfilUploadBillede_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "Vælg dit profilbillede";
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png";
if (op.ShowDialog() == true)
{
try
{
//Skriv data til SQL
using (SqlConnection conn = new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Database=fraekt;Trusted_Connection=True"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "UPDATE profil SET Billede='" + new Uri(op.FileName) + "' WHERE Email='" + Config.profil_email + "'";
cmd.Connection = conn;
conn.Open();
int rowsAffected = cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show("A handled exception just occurred: " + ex.Message, "Exception Sample", MessageBoxButton.OK, MessageBoxImage.Warning);
}
finally
{
ProfilbilledeBig.Source = new BitmapImage(new Uri(op.FileName));
profilbillede.Source = new BitmapImage(new Uri(op.FileName));
}
}
}
这是我的XAML:
<Button x:Name="ProfilUploadBillede" Content="UPLOAD BILLEDE" HorizontalAlignment="Left" Height="37" Margin="187,391,0,0" VerticalAlignment="Top" Width="218" BorderBrush="#FFC11E2F" Background="#FFC11E2F" Foreground="White" FontSize="16" Cursor="Hand" Click="ProfilUploadBillede_Click"/>
修改编辑 我通过添加
来修复它finally
{
ProfilbilledeBig.Source = new BitmapImage(new Uri(op.FileName));
profilbillede.Source = new BitmapImage(new Uri(op.FileName));
}
到我的代码:)