How Change Something in View from Presentation in Prism?

Topics: Prism v2 - Silverlight 4
Jul 7, 2010 at 4:43 AM

I want to change something in view(user-control) from itself Presentation. For example i want to change button text(or change an image-Source of image) from Presentation.
change something refer to make a change in Controls-visual or something like that.
so How I do That?

 

Jul 8, 2010 at 3:17 PM

Hi,

if you need to modify the appearance of a view based on an event that occurs in the view (for example, changing the text of a button when you click it), you can do it using the mechanisms provided by WPF/Silverlight directly. For example you could use code behind, triggers or bindings.

if you need to modify the appearance of a view based on an event that occurs on the model, or based on some business logic (for example, showing a particular image depending on the value of the model), you can use binding to the ViewModel using the MVVM pattern:

Please let me know if this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero

Jul 11, 2010 at 4:22 AM
@fantivero sorry but i use prism ver2, and I don't think that use MVVM pattern. so Your solution cant help me! also I wont change them by triggers. Let explain what I want to do? In presentation Class within occurred method, I checked ‍Condition and then if result was true, then change image-source of an image-control. @fantivero thank you cuz you Attention to my problem. :) regards Rev
Jul 12, 2010 at 3:52 AM

My http://ehr.CodePlex.com (folder ModularityWithMef.Desktop) is a Prism V4 Drop 3 prototype using the MVPVM pattern w/MEF container - the principals still apply regardless of version or pattern.   I have a property "ModuleStatus" that will swap out smiley images; if ModuleStatus="Initialized" (indicating module is loaded) then a happy smiley appears.  

An except from the Themes/ModularityControl.generic.xaml file follows:   I name my Image "ModuleImage" so that within my trigger I can change its source when ModuleStatus value="Initialized". 

        ...
...                          
        <Grid Grid.Row="2">
            <Viewbox Height="15" x:Name="ModuleImageContainer">
                <Image x:Name="ModuleImage" Source="/GWN.Library.WPF;component/Images/smiley1.gif" />
            </Viewbox>
        </Grid>
    </Grid>
</Border>
<ControlTemplate.Triggers>
    <Trigger Property="ModuleStatus" Value="Initialized">
        <Setter TargetName="ModuleImage" Property="Source" Value="/GWN.Library.WPF;component/Images/smiley2.gif"/>
        <Setter TargetName="ModuleImageContainer" Property="Height" Value="18"/>
        <Setter Property="Background" Value="{DynamicResource ModuleControl.Initialized.BackgroundBrush-Simple}"/>
        <Setter Property="Foreground" Value="{DynamicResource ModuleControl.Initialized.ForegroundBrush-Simple}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource ModuleControl.Initialized.BorderBrush-Simple}"/>
        <Setter Property="FontSize" Value="14.667"/>
    </Trigger>

RevCode wrote:
@fantivero sorry but i use prism ver2, and I don't think that use MVVM pattern. so Your solution cant help me! also I wont change them by triggers. Let explain what I want to do? In presentation Class within occurred method, I checked ‍Condition and then if result was true, then change image-source of an image-control. @fantivero thank you cuz you Attention to my problem. :) regards Rev