עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Image source שלא מתעדכן דרך binding ב wpf

Featured Replies

פורסם

יצרתי wpf user control

זה הקוד:


<UserControl x:Class="MonopolyMVVM.View.PlayerDetails"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="35" d:DesignWidth="300" Loaded="UserControl_Loaded">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="102*"/>
<ColumnDefinition Width="143*"/>
<ColumnDefinition Width="55*"/>
</Grid.ColumnDefinitions>
<Image x:Name="imagePlayerObject" Source="{Binding Path=Imagesource ,Mode=TwoWay}" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"></Image>
<TextBox x:Name="txtPlayerName" Grid.Column="1" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Text="{Binding Path=Name}"></TextBox>
<Label x:Name="lblPlayerNumber" Grid.Column="0" HorizontalContentAlignment="Left" VerticalContentAlignment="Center"></Label>
</Grid>
</UserControl>

מה שאני רוצה לעשות זה בלחיצה על כפתור שאני אשים תמונה בתוך הimage

לכן יצרתי binding עם מאפיין שיצרתי בcode behaind

זה המאפיין וככה הגדרתי אותו



Uri _imagesource;
public Uri Imagesource
{
get { return (Uri)GetValue(UriSourceProperty); }
set
{
SetValue(UriSourceProperty, value);
if(PropertyChanged!=null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Imagesource"));
}

}
}
public static DependencyProperty UriSourceProperty = DependencyProperty.Register("Imagesource", typeof(Uri), typeof(PlayerDetails));

כמו שאתם רואים דאגתי שהמאפיין ידאג ליידע את הview שהוא השתנה, ( INotifyPropertyChanged) והגדרתי את אותו מאפיין כdependency property

וכאשר יצרתי אובייקט בview מסוג user control כמו בקוד הבא:


<View:PlayerDetails x:Name="One" Grid.Row="0" Imagesource="{Binding Path=Test ,Mode=TwoWay}" LblPlayerNumber="Player One :" Visibility="{Binding Path=PlayerOneVisibility}"></View:PlayerDetails>

דאגתי לקשור אותו למשתנה בview model מסוג Uri , ( המאפיין Test הוא מסוג Uri) וכאשר אני יוצר אירוע של לחיצה אני מציב בTest את השורה הבאה :


test = new Uri("pack://application:,,,/Resources/Images/Players/personA.png");

משום מה התמונה בתוך הImage control שנמצא בתוך הuser control לא מתעדכנת... אשמח לעזרה

קראתי באינטרנט וכל הדוגמאות וההסברים שרשמו לא עובדים

מה הבעיה :(

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.