פורסם 2014 באוקטובר 1311 שנים יצרתי 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 לא מתעדכנת... אשמח לעזרה קראתי באינטרנט וכל הדוגמאות וההסברים שרשמו לא עובדים מה הבעיה
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.