Search This Blog

Wednesday, August 31, 2011

Show PRISM message box; Display message box using PRISM MVVM Silverlight

We want to display a message box with the help of PRISM in Silverlight.
There is a different class for displaying an question - Confirmation. We
can display our own window with InteractionRequest<OurViewModel> and some code in XAML
defining which view to run.


Message box class in defined in PRISM's namespace:
namespace: Microsoft.Practices.Prism.Interactivity.InteractionRequest

Class name is Notification.

SomeView, XAML:

<UserControl x:Class="WebClient.SomeView"
..... >

    <Grid x:Name="LayoutRoot" Background="White">
        <i:Interaction.Triggers>
            <prism:InteractionRequestTrigger SourceObject="{Binding SaveNotification}">
                <prism:PopupChildWindowAction/>
            </prism:InteractionRequestTrigger>
        </i:Interaction.Triggers>
    </Grid>
</UserControl>

SomeViewModel, cs:

public class SomeViewModel
{
    public SomeViewModel(......)
    {
        saveNotification = new InteractionRequest<Notification>();
    }

    private readonly InteractionRequest<Notification> saveNotification;

    //this function displays message box
    private void someFunction(object obj)
    {
        //show message box
        ((InteractionRequest<Notification>)saveNotification).Raise(new Notification { Title = "Information", Content = "User was saved." });           
    }

    public IInteractionRequest SaveNotification
    {
        get { return this.saveNotification; }
    }
}

Set property in View from ViewModel in MVVM using Interaction Triggers; Set View's property from ViewModel without code behind in Silverlight 4.0

We have a View which is a Window control with DialogResult property and we want to set this property to True without using code behind.

<controls:ChildWindow  x:Class="WebClient.Views.ConfWorkerView"

   xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
   xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
   xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions”
Name="Window" >

  <UserControl>
    <Grid>
    <Button HorizontalAlignment="Right" Content="Save"  Command="{Binding SaveCommand}" >
          <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
               <ei:ChangePropertyAction PropertyName="DialogResult" Value="True" TargetName="Window"/>
            </i:EventTrigger>
          </i:Interaction.Triggers>
       </Button>
    <Grid>
  <UserControl>
</controls:ChildWindow>

Tuesday, August 23, 2011

PRISM passing data in RegionContext

Define region in the following way - with regionName and region context defined

xmlns:regions="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism"

<ItemsControl MinHeight="400" regions:RegionManager.RegionName="RCP.WorkerShowPersonalDataRegion" regions:RegionManager.RegionContext="{Binding Path=CurrentWorker, Mode=TwoWay}" >
    <!-- PRISM registers various types of configuration views here -->
</ItemsControl>

 

Receive Context in ViewModel like this:
this.RegionContext = regionManager.Regions[RegionNames.WorkerShowPersonalDataRegion].Context;

This can be done in Constructor or e.g. OnNavigatedTo method from PRISM INavigationAware.

PRISM region in ItemsControl, Region.RegionContext is null when deleting views from region

When you delete views from your region, the RegionContext is set to null. This is probably done to
prevent memory leaks but is really frustrating at the beginning. To prevent RegionContext from being
deleted you have two options:
1) use <ContentControl as your region control. In this solution views will be replace and you won't have to delete view from region thus preventing RegionContext from being nulled
2) Clone the object that you set as RegionContext (not really a neat solution)

//delete views from your region
IViewsCollection views = regionManager.Regions[RegionNames.WorkerShowPersonalDataRegion].Views;
int count = views.Count();
foreach (var view in views)
{
    regionManager.Regions[RegionNames.WorkerShowPersonalDataRegion].Remove(view);
}
regionManager.Regions[RegionNames.WorkerShowPersonalDataRegion].Context = new Worker(CurrentWorker);

Wednesday, July 27, 2011

Subtitles out of sync Samsung PS51D6900; Subtitles out of sync in Samsung’s plasma TV 50’’

Subtitles in Samsung plasma does not always work as we would like them to. I had several movies which had problems with subtitles. It turned out that it was a problem with frame rate (of 25 frames/s in my case) which Samsung’s plasmas interpret in a wrong way. The symptoms were as follows: subtitles worked correctly in Media Player Classic Home Cinema (link) but failed to work on the TV.

The problem was that these subtitles were FRAME-based. It means that the format was like this:

{3955}{4015}Do roboty!
{4021}{4112}Potrafisz byµ dupkiem, jeśli chcesz.
{4165}{4230}Głupia dziwka.
{4300}{4354}Zamknijcie lokal, gdy skończycie.

That is: {Beginning_frame}{Ending_frame}

If you want the subtitles to work in both: MPC-HC & Samsung plasma you need to convert them to srt format which looks like this:

11
00:00:53,520 --> 00:00:55,760
Czyli dobrze usłyszałem.
Powtarzasz to co roku.

12
00:00:55,920 --> 00:00:57,720
Tak, ale tym razem mówię poważnie.

13
00:00:57,880 --> 00:00:59,320
W końcu żyje się tylko raz.

14
00:00:59,480 --> 00:01:00,440
Pewnie.

 

Generally ANY format which is TIME-based should work. A nice program for converting subtitles to time-based formats is here. You can download a version here as well.

Tuesday, July 26, 2011

Visual Studio 2010 reference other project from the same Solution

- Add a reference to that Project int the Project you're trying to access foreign classes from
  (Add reference-Projects-Foreign_Project)
- Make sure when compiling (debug), your solution platform is set to "Any CPU"
- Make sure they both are referencing the same .Net 4 Profile, one may be using the client profile

Monday, July 25, 2011

Joomla - Re: JAuthentication::__construct: Could not load authentication libraries

I disabled the plugin - Authentication – Joomla as I thought it was for user logging in the page, not the admin login. It was a big mistake though. To turn this feature on you need to log to Joomla’s database and change published to 1 in the jos_plugins table  in row.Name = Authentication – Joomla (it was row.id = 1 in my case).

UPDATE `your_database_name`.`jos_plugins` SET `published` = '1' WHERE `jos_plugins`.`id` =1;