Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:48:21+00:00 2026-06-03T05:48:21+00:00

I have created a UserControl name TitleBar, which is placed in every view. The

  • 0

I have created a UserControl name TitleBar, which is placed in every view.

The TitleBar.xaml contains a Button to close the Window in which it contain.

How can i close a Caliburn Window using that Button.

TitleBar UserControl

<UserControl x:Class="JIMS.Controls.TitleBar"
             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">
    <Grid Style="{StaticResource TitleBar}">
        <Rectangle HorizontalAlignment="Stretch" Height="7" Margin="0,0,-5,0" VerticalAlignment="Top" Fill="{DynamicResource DefaultBrush}"></Rectangle>
        <Grid HorizontalAlignment="Left" Margin="-10,-5,0,0" Name="Logo">
            <TextBlock Name="txtTitle" Style="{StaticResource Title}">JIMS</TextBlock>            
            <Ellipse HorizontalAlignment="Right" Margin="0,0,5,0" Width="20" Height="20">
                <Ellipse.Fill>
                    <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_settings_white}" />
                </Ellipse.Fill>
            </Ellipse>
        </Grid>
        <Grid HorizontalAlignment="Right">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,-4,0">
                <Button Name="btnClose" Style="{StaticResource ChromeButtonStyle}" Click="btnClose_Click" IsTabStop="False">
                    <TextBlock  TextWrapping="Wrap" Text="r" FontFamily="Webdings" Foreground="#FF919191" FontSize="13.333" />
                </Button>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>

TitleBar Usage in a View

<UserControl xmlns:my="clr-namespace:JIMS.Controls;assembly=JIMS.Controls"  x:Class="JIMS.Views.Stock.UnitView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        
        Name="Unit">        
    <Border Style="{StaticResource WindowBorderStyle}">
        <StackPanel Orientation="Vertical">
            <my:TitleBar Title="unit creation"/>
            <StackPanel Visibility="{Binding ControlVisiblity}" Orientation="Horizontal" Margin="0,5,0,5">
                <StackPanel Orientation="Vertical" Margin="10,0,0,0">
                    <Label>Short Name :</Label>
                    <Label>Unit Name :</Label>                    
                </StackPanel>
                <StackPanel Orientation="Vertical" Width="200" Margin="0,0,10,0">
                    <TextBox Name="txtShortName" Text="{Binding Path=UnitShort}"></TextBox>
                    <TextBox Name="txtUnitName" Text="{Binding Path=UnitName}"></TextBox>                    
                </StackPanel>
            </StackPanel>
            <Expander Style="{StaticResource DisplayExpander}" IsExpanded="{Binding IsDisplayExpanded}" Header="display units">
                <StackPanel Orientation="Horizontal" Margin="0,5,0,5" Visibility="{Binding DisplayVisiblity}">
                    <DataGrid AutoGenerateColumns="True" Height="200" MinWidth="300" ItemsSource="{Binding Display}"></DataGrid>
                </StackPanel>
            </Expander>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Name="SaveUnit" Style="{StaticResource MetroButton}">Save</Button>
            </StackPanel>
        </StackPanel>
    </Border>
</UserControl>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:48:22+00:00Added an answer on June 3, 2026 at 5:48 am

    In your TitleBar control define a RoutedEvent like this

            public event RoutedEventHandler CloseClick
        {
            add { AddHandler(CloseClickEvent, value); }
            remove { RemoveHandler(CloseClickEvent, value); }
        }
    
        public static readonly RoutedEvent CloseClickEvent = EventManager.RegisterRoutedEvent(
            "CloseClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TitleBar));
    
        void RaiseCloseClickEvent()
        {
            var newEventArgs = new RoutedEventArgs(TitleBar.CloseClickEvent);
            RaiseEvent(newEventArgs);
        }
    
        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            RaiseCloseClickEvent();
        }
    

    And attach the btnClose_Click event handler to the btnClose control in your TitleBar

    Now, when you use your TitleBar add an action like this

            <my:TitleBar Title="This is the title">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="CloseClick">
                        <cal:ActionMessage MethodName="Close"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </my:TitleBar>
    

    This will call the method Close on your viewmodel when the the CloseClickEvent is raised on the TitleBar.

    For closing the window, you could derive your viewmodel from Screen and add the following snippet

    public void Close()
    {
        TryClose();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

within a ascx (usercontrol) I have a created a tab section which contains a
I have a user control created in xaml, lets name it View. In the
I have created a UserControl as follows: <UserControl x:Class=MySample.MyControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=using:MySample xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
I have a custom usercontrol created by myself which belongs to mine baseControls elements.
I have a page with a UserControl (in which linkbuttons are dynamically created). On
I have created a UserControl called AutorControl with a method to clear its textbox:
I have created a UserControl that has 3 panels. What I what to do
I have created a user control (CheckedDirTree) that exposes a CheckedFolder property which in
I have created an Address user control which is as follow: <%@ Control Language=C#
I have created a web user control (MemberDetails.ascx) which is loaded dynamically on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.