Click here to Skip to main content
15,039,359 members
Home / Discussions / WPF
   

WPF

 
QuestionMake textbox fill up and resizie Pin
Acuena21-Jun-21 20:59
MemberAcuena21-Jun-21 20:59 
AnswerRe: Make textbox fill up and resizie Pin
Richard Deeming21-Jun-21 21:58
mveRichard Deeming21-Jun-21 21:58 
AnswerRe: Make textbox fill up and resizie Pin
Gerry Schmitz22-Jun-21 7:07
mveGerry Schmitz22-Jun-21 7:07 
Question[Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
Oscar Tsai18-Jun-21 7:34
MemberOscar Tsai18-Jun-21 7:34 
AnswerRe: [Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
Gerry Schmitz19-Jun-21 14:29
mveGerry Schmitz19-Jun-21 14:29 
GeneralRe: [Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
Oscar Tsai20-Jun-21 3:20
MemberOscar Tsai20-Jun-21 3:20 
GeneralRe: [Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
Gerry Schmitz20-Jun-21 6:01
mveGerry Schmitz20-Jun-21 6:01 
AnswerRe: [Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
Richard Deeming20-Jun-21 23:37
mveRichard Deeming20-Jun-21 23:37 
Quote:
DisplayView.xaml
XAML
<Page.DataContext>
    <vm:DisplayViewModel/>
</Page.DataContext>
...
<Image x:Name="imgDisplayView" Source="{Binding ImagePath}">
	<Image.RenderTransform>
		<TransformGroup>
			<TranslateTransform/>
			<RotateTransform/>
			<ScaleTransform/>
		</TransformGroup>
	</Image.RenderTransform>
</Image>
...
The problem is that your DisplayPanelView is setting its DataContext to a new instance of your viewmodel. The image path you set on the DataContext of the DisplayControlView will have no effect on the property of the separate viewmodel instance used as the DataContext for DisplayPanelView.

You need both controls to use the same viewmodel instance for their DataContext. Depending on how your ReviewView viewmodel is set up, you probably want to expose a single DisplayViewModel instance as a property on that viewmodel, and have both Display... views bound to that.

For example:
C#
public class ReviewViewModel : ViewModelBase
{
    private DisplayViewModel _display = new DisplayViewModel();
    
    public DisplayViewModel
    {
        get { return _display; }
        set { SetValue(ref _display, value); }
    }
}
ReviewView.xaml:
XAML
<views:DisplayControlView DataContext="{Binding Path=DisplayViewModel}" />
<views:DisplayPanelView DataContext="{Binding Path=DisplayPanelView}" />
Remove the <Page.DataContext> from both DisplayControlView and DisplayPanelView pages.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: [Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
Oscar Tsai21-Jun-21 4:10
MemberOscar Tsai21-Jun-21 4:10 
GeneralRe: [Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
Oscar Tsai21-Jun-21 16:11
MemberOscar Tsai21-Jun-21 16:11 
AnswerRe: [Problem] Why can not Pass Image between 2 Views by using the same ViewModel (MVVM) Pin
michaelbarb23-Sep-21 10:32
Membermichaelbarb23-Sep-21 10:32 
QuestionProblem Setting Focus Pin
Kevin Marois24-May-21 9:39
professionalKevin Marois24-May-21 9:39 
AnswerRe: Problem Setting Focus Pin
Richard Deeming24-May-21 21:56
mveRichard Deeming24-May-21 21:56 
QuestionImpossible to override a value in an animation located in a style? Pin
Mc_Topaz20-May-21 6:51
MemberMc_Topaz20-May-21 6:51 
AnswerRe: Impossible to override a value in an animation located in a style? Pin
Gerry Schmitz20-May-21 8:08
mveGerry Schmitz20-May-21 8:08 
QuestionApp Security Behavior Pin
Kevin Marois20-May-21 6:09
professionalKevin Marois20-May-21 6:09 
QuestionOverride a value in base style's resource Pin
Mc_Topaz20-May-21 2:45
MemberMc_Topaz20-May-21 2:45 
AnswerRe: Override a value in base style's resource Pin
Richard Deeming20-May-21 4:33
mveRichard Deeming20-May-21 4:33 
GeneralRe: Override a value in base style's resource Pin
Mc_Topaz20-May-21 6:00
MemberMc_Topaz20-May-21 6:00 
QuestionApply TextBlock Captions at Runtime Pin
Kevin Marois14-May-21 9:34
professionalKevin Marois14-May-21 9:34 
AnswerRe: Apply TextBlock Captions at Runtime Pin
Peter_in_278014-May-21 13:36
professionalPeter_in_278014-May-21 13:36 
GeneralRe: Apply TextBlock Captions at Runtime Pin
Kevin Marois14-May-21 13:42
professionalKevin Marois14-May-21 13:42 
GeneralRe: Apply TextBlock Captions at Runtime Pin
Pete O'Hanlon14-May-21 23:51
mvePete O'Hanlon14-May-21 23:51 
AnswerRe: Apply TextBlock Captions at Runtime Pin
Mycroft Holmes15-May-21 12:25
professionalMycroft Holmes15-May-21 12:25 
GeneralRe: Apply TextBlock Captions at Runtime Pin
Gerry Schmitz16-May-21 11:17
mveGerry Schmitz16-May-21 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.