Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

ModalControl RSS

6 replies

Last post Jul 01, 2009 11:32 AM by varshavmane

(0)
  • slen

    slen

    Member

    10 Points

    59 Posts

    ModalControl

    Jul 01, 2009 08:21 AM | LINK

    I want to create a popup. By looking at the example of C#, I would like to know what library that ModalControl belong to. Is there any VB.NET sample?

    Do I need to install silverlight 3 in order to have the pop up done, currently I am using silverlight 2.

     

    Thanks

     

  • mchlSync

    mchlSync

    Star

    14968 Points

    2799 Posts

    Re: ModalControl

    Jul 01, 2009 08:31 AM | LINK

    You can use <POPUP > tag in XAML .. Are you talking about Silverlight build-in Popup control or Custom Model Control?
    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Regards,
    Michael Sync
    Silverlight MVP

    Blog : http://michaelsync.net
  • varshavmane

    varshavmane

    Star

    13229 Points

    2753 Posts

    Re: ModalControl

    Jul 01, 2009 08:37 AM | LINK

    Hi,

    I have already replied to your post on:

    http://silverlight.net/forums/p/104797/240066.aspx#240066

    You dont need to install Silverlight 3. You just need to have the Class which they have used.

    Is there any problem that you are facing while converting that class into VB?

    Please "Mark as Answer" if this post answered your question. :)
    Visit my Blog
  • slen

    slen

    Member

    10 Points

    59 Posts

    Re: Re: ModalControl

    Jul 01, 2009 08:39 AM | LINK

    I am looking into both, the built-in Popup control and the custom Model control. Do you have any sample for both ... vb.net preferable. If I am looking for the custom one, which library that ModalControl belong to? 

     Thanks

     

  • slen

    slen

    Member

    10 Points

    59 Posts

    Re: Re: ModalControl

    Jul 01, 2009 08:49 AM | LINK

    Yes. Because I cannot find the "ModalControl" class in the library at the same time I am looking for some options.

     

    Thanks


  • varshavmane

    varshavmane

    Star

    13229 Points

    2753 Posts

    Re: Re: ModalControl

    Jul 01, 2009 09:39 AM | LINK

    Hi,

    Please donwload the Project from this http://www.codeproject.com/KB/silverlight/slmodal/ModalWizard.zip link. When you open the zip file you will find a Folder name Model which has ModelControl.cs class.

    Just convert it into VB.

    HTH [:)]

    Please "Mark as Answer" if this post answered your question. :)
    Visit my Blog
  • varshavmane

    varshavmane

    Star

    13229 Points

    2753 Posts

    Re: Re: ModalControl

    Jul 01, 2009 11:32 AM | LINK

    Hi,

    Here is the ModelControl Class which I have converted into VB:

    NOTE: I have not tested it whether it works properly or not but Im sure it will work.

     

    Imports System

    Imports System.Windows

    Imports System.Windows.Controls

    Imports System.Windows.Controls.Primitives

    Imports System.Windows.Input

    Imports System.Windows.Media

     

    Public Enum ExitCode

    Cancel

    OK

    End Enum

    Public Delegate Function ModalClosing(ByVal sender As Object, ByVal e As ExitCode) As Boolean

    Public Class ModalControl

    Private Class ModalHost

    Inherits UserControl

    Private _oBgCanvas As Canvas

    Private _oUserCtrl As UserControl

    Private _oParent As Grid

    Public ReadOnly Property ChildControl() As UserControl

    Get

    Return _oUserCtrl

    End Get

    End Property

    Friend Sub New(ByVal oParent As Grid, ByVal oControl As UserControl)

    _oParent = oParent

    _oUserCtrl = oControl

    _oBgCanvas =
    New Canvas()_oBgCanvas.Background = New SolidColorBrush(Color.FromArgb(0, 0, 0, 0))

    _oBgCanvas.Children.Clear()

    _oBgCanvas.Children.Add(_oUserCtrl)

    Content = _oBgCanvas

    AddHandler Application.Current.Host.Content.Resized, AddressOf OnHostResized

    AddHandler Loaded, AddressOf OnHostLoaded

    End Sub

    Friend Sub Close()

    RemoveHandler Application.Current.Host.Content.Resized, AddressOf OnHostResized

    RemoveHandler Loaded, AddressOf OnHostLoaded

    RemoveHandler _oUserCtrl.MouseLeftButtonDown, AddressOf OnMouseLeftButtonDown

    RemoveHandler _oUserCtrl.MouseLeftButtonUp, AddressOf OnMouseLeftButtonUpRemoveHandler _oUserCtrl.MouseMove, AddressOf OnMouseMove

    _oBgCanvas.Children.Clear()

    End Sub

    Private Sub OnHostLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded

    RemoveHandler _oUserCtrl.MouseLeftButtonDown, AddressOf OnMouseLeftButtonDown

    AddHandler _oUserCtrl.MouseLeftButtonUp, AddressOf OnMouseLeftButtonUpAddHandler _oUserCtrl.MouseMove, AddressOf OnMouseMove

    _oUserCtrl.Focus()

    _oUserCtrl.TabNavigation = KeyboardNavigationMode.Cycle

    ' Resize background canvas

    ' ----------------------------------------

    _oBgCanvas.Width = _oParent.ActualWidth

    _oBgCanvas.Height = _oParent.ActualHeight

    OnHostResized(
    Nothing, EventArgs.Empty)

    End Sub

    Private Sub OnHostResized(ByVal sender As Object, ByVal e As EventArgs)

    ' Centre window

    ' ----------------------------------------

    If _oUserCtrl IsNot Nothing AndAlso Not Double.IsNaN(_oUserCtrl.Width) AndAlso Not Double.IsNaN(_oParent.ActualWidth) Then

    _oUserCtrl.SetValue(Canvas.LeftProperty, (_oBgCanvas.Width - _oUserCtrl.Width) / 2)

    End If

    If _oUserCtrl IsNot Nothing AndAlso Not Double.IsNaN(_oUserCtrl.Height) AndAlso Not Double.IsNaN(_oParent.ActualHeight) Then

    _oUserCtrl.SetValue(Canvas.TopProperty, (_oBgCanvas.Height - _oUserCtrl.Height) / 2)

    End If

    End Sub

    #Region "Dragging code"

    Private _bMouseCapturing As Boolean = False

    Private _oLastMousePos As New Point()Private Overloads Sub OnMouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown

    _bMouseCapturing = _oUserCtrl.CaptureMouse()

    _oLastMousePos = e.GetPosition(Nothing)

    End Sub

    Private Overloads Sub OnMouseLeftButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs) Handles Me.MouseLeftButtonUp

    If _bMouseCapturing Then

    _oUserCtrl.ReleaseMouseCapture()

    _oLastMousePos =
    New Point()

    _bMouseCapturing = False

    End If

    End Sub

    Private Overloads Sub OnMouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove

    If _bMouseCapturing = False Then

    Exit Sub

    End If

    Dim oHostPoint As Point = e.GetPosition(ParentHost)

    Dim oMousePoint As Point = e.GetPosition(Nothing)

    Dim dHostX As Double = Math.Abs(oMousePoint.X - oHostPoint.X)

    Dim dHostY As Double = Math.Abs(oMousePoint.Y - oHostPoint.Y)

    Dim dblX As Double = CDbl(_oUserCtrl.GetValue(Canvas.LeftProperty)) + oMousePoint.X - _oLastMousePos.X

    Dim dblY As Double = CDbl(_oUserCtrl.GetValue(Canvas.TopProperty)) + oMousePoint.Y - _oLastMousePos.Y

    If dblX > -dHostX AndAlso dblX + _oUserCtrl.ActualWidth < _oParent.ActualWidth + dHostX Then

    _oUserCtrl.SetValue(Canvas.LeftProperty, dblX)

    End If

    If dblY > -dHostY AndAlso dblY + _oUserCtrl.ActualHeight < _oParent.ActualHeight + dHostY Then

    _oUserCtrl.SetValue(Canvas.TopProperty, dblY)

    End If

    _oLastMousePos = oMousePoint

    End Sub

    #End Region

    End Class

     

    #Region "Modal handlers"

    Shared _oParentHost As Grid = Nothing

    Private _oControlPopup As Popup = Nothing

    Private _oBgPopup As New Popup()

    Private _oBgCanvas As New Canvas()

    Public Shared Property ParentHost() As Grid

    Get

    Return _oParentHost

    End Get

    Set(ByVal value As Grid)

    _oParentHost = value

    End Set

    End Property

    Public Sub ShowModal(ByVal oCtrl As UserControl)

    ' Show the dimmed background

    ' -----------------------------------

    _oBgCanvas.Background = New SolidColorBrush(Color.FromArgb(70, 0, 0, 0))

    _oBgPopup.Child = _oBgCanvas

    OnHostResized(
    Nothing, EventArgs.Empty)

    _oBgPopup.IsOpen = True

    AddHandler Application.Current.Host.Content.Resized, AddressOf OnHostResized

    ' Show user control

    ' -----------------------------------

    _oControlPopup = New Popup()

    _oControlPopup.Child = New ModalHost(_oParentHost, oCtrl)

    If _oParentHost IsNot Nothing Then

    _oParentHost.Children.Insert(0, _oControlPopup)

    End If

    _oControlPopup.IsOpen = True

    End Sub

    Private Sub OnHostResized(ByVal sender As Object, ByVal e As EventArgs)

    _oBgCanvas.Width = Application.Current.Host.Content.ActualWidth

    _oBgCanvas.Height = Application.Current.Host.Content.ActualHeight

    End Sub

    Public Function HideModal() As UserControl

    Dim oRet As UserControl = Nothing

    If _oControlPopup IsNot Nothing Then

    _oControlPopup.IsOpen = False

    If _oParentHost IsNot Nothing Then

    _oParentHost.Children.Remove(_oControlPopup)

    End If

    Dim oHost As ModalHost = TryCast(_oControlPopup.Child, ModalHost)

    If oHost IsNot Nothing Then

    oRet = oHost.ChildControl

    oHost.Close()

    End If

    _oControlPopup.Child = Nothing

    _oControlPopup = Nothing

    End If

    If _oBgPopup IsNot Nothing Then

    _oBgPopup.IsOpen = False

    End If

    Return oRet

    End Function

    #End Region

    End Class

    HTH [:)]

    Please "Mark as Answer" if this post answered your question. :)
    Visit my Blog