Open new Window by click the button

Nov 18, 2010 at 8:34 AM

I don't find this in documentation. I need to open new window by clicking the button.

My XAML code:

<Fluent:Button x:Name="QUIKsettings" Text="checkQUIK" Icon="/Images/QUIKinfo.png" Click="ButtonClick">OpenSettings</Fluent:Button>

My C# code:

private void ButtonClick(object sender, EventArgs e)
        {
            QUIKsettings win = new QUIKsettings();
        }
Please tell me where I made a mistake.

Coordinator
Nov 18, 2010 at 9:46 AM

win.ShowDialog()?

Nov 18, 2010 at 10:34 AM

I already have a window (QUIKsettings) that I want to show by clicking on the button

Can you show an example of code to open a new window (XAML and C#)?

Coordinator
Nov 18, 2010 at 10:59 AM

QUIKsettings win = new QUIKsettings();
win.ShowDialog();

Nov 18, 2010 at 12:28 PM

What does it mean: "Error 1: "Fluent.Sample.Foundation.Window" does not contain a definition for "ButtonClick" and was not found extension method "ButtonClick", taking the type of "Fluent.Sample.Foundation.Window" as the first argument (possibly missing directive using or assembly reference)"

Nov 19, 2010 at 1:39 AM
sotikov wrote:

I don't find this in documentation. I need to open new window by clicking the button.

My XAML code:

 

<Fluent:Button x:Name="QUIKsettings" Text="checkQUIK" Icon="/Images/QUIKinfo.png" Click="ButtonClick">OpenSettings</Fluent:Button>

 

My C# code:

 

private void ButtonClick(object sender, EventArgs e)
        {
            QUIKsettings win = new QUIKsettings();
        }
Please tell me where I made a mistake.

 

I'm guessing you're using Fluent 1.3 since Text is no longer supported by 2.0.

 

Try 

<Fluent:Button Name="QUIKsettings" Text="checkQUIK" Icon="/Images/QUIKinfo.png" Click="ButtonClick">OpenSettings</Fluent:Button>

and 
private void ButtonClick(object sender, RoutedEventArgs e)
instead of just EventArgs.

Hope that helps.

Nov 19, 2010 at 8:35 AM

With this code

XAML:

<Fluent:Button Name="QUIKsettings" Text="checkQUIK" Icon="/Images/QUIKinfo.png" Click="ButtonClick">OpenSettings</Fluent:Button>
C#:
private void ButtonClick(object sender, RoutedEventArgs e)
        {
            QUIKsettings win = new QUIKsettings();
            win.ShowDialog();
        }

, gives: Error 1 Property "Fluent.Button.Text" is already set and can be set only once. Line 34 Position 131.

There's something with the XAML code. VS2010 shows an error in the XAML.

Coordinator
Nov 19, 2010 at 9:11 AM

Text is the content property, so you must leave only one: checkQUIK or OpenSettings.

Daniel

Nov 19, 2010 at 9:57 AM

VS2010 shows an error only when I add the XAML code Click = "ButtonClick"

Nov 19, 2010 at 10:07 AM
daVinci wrote:

Text is the content property, so you must leave only one: checkQUIK or OpenSettings.

Daniel

I corrected, but still there is a bug

Coordinator
Nov 19, 2010 at 10:16 AM

Write here your current code.

Nov 19, 2010 at 11:33 AM
Edited Nov 19, 2010 at 11:38 AM

OK!

MainWindow XAML:

 

<Fluent:RibbonWindow
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="MainWindow" x:Class="Fluent.Sample.Foundation.Window"
    Title="MainWindow" Width="500" Height="350" Foreground="White">
	<Fluent:RibbonWindow.Background>
		<LinearGradientBrush EndPoint="1,4" StartPoint="0,0">
			<GradientStop Color="#FF323246" Offset="0"/>
			<GradientStop Offset="1" Color="White"/>
		</LinearGradientBrush>
	</Fluent:RibbonWindow.Background>
    <Grid>
    	<Fluent:Ribbon x:Name="Ribbon" BackstageBrush="#FF32A050" VerticalAlignment="Stretch" d:LayoutOverrides="Height" >
            <!--Contextual Tab Groups-->
            <Fluent:Ribbon.ContextualGroups>
            	<Fluent:RibbonContextualTabGroup Header="Tools" x:Name="toolsGroup" Background="Gold" BorderBrush="Gold" Visibility="Visible" />
            </Fluent:Ribbon.ContextualGroups>

            <!--Quick Access Toolbar Items-->
            <Fluent:Ribbon.QuickAccessItems>
                <!--Use Content or Target Property to set QAT item-->
                <Fluent:QuickAccessMenuItem Target="{Binding ElementName=QUIKsettings}" />
                <!--You Can Just Bind with Any Control-->
            	<Fluent:QuickAccessMenuItem Target="{Binding ElementName=buttonGreen}"/>
            </Fluent:Ribbon.QuickAccessItems>

            <!--Backstage Items-->
            <Fluent:Ribbon.BackstageItems>
            	<Fluent:BackstageTabItem Header="New">
                    <Fluent:Button Text="Red" Foreground="#FF000000" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" />    		        	
				</Fluent:BackstageTabItem>
            	<Fluent:BackstageTabItem Header="Print"/>
                <Fluent:Button x:Name="QUIKsettings" Text="settings" Icon="/Images/QUIKinfo.png" Fluent:KeyTip.Keys="Q" Click="ButtonClick" ></Fluent:Button>
            </Fluent:Ribbon.BackstageItems>
        	<Fluent:RibbonTabItem x:Name="MainTab" Header="Main" BorderBrush="Black" Fluent:KeyTip.Keys="M">
        		<Fluent:RibbonGroupBox Header="Group">
                    <Fluent:Button x:Name="buttonGreen" Text="Green" />
        			<Fluent:Button x:Name="buttonGray" Text="Grey" />
        		</Fluent:RibbonGroupBox>
        	</Fluent:RibbonTabItem>

            <!--Contextual Tabs-->
            <Fluent:RibbonTabItem Header="Contextual Tab" Group="{Binding ElementName=toolsGroup}">
            	<Fluent:RibbonGroupBox Header="Group">
            		<Fluent:Button x:Name="buttonGray1" Text="Grey" />
            		<Fluent:Button x:Name="buttonGreen1" Text="Green" />
            	</Fluent:RibbonGroupBox>
            </Fluent:RibbonTabItem>

        </Fluent:Ribbon>
    </Grid>
</Fluent:RibbonWindow>

 

MainWindow C#:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Fluent;

namespace HeadSharpFluent
{
    /// <summary>
    /// MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            throw new NotImplementedException();
        }

        private void QUIKsettings_Click(object sender, RoutedEventArgs e)
 { QUIKsettings win = new QUIKsettings(); win.ShowDialog(); } } }

 

Nov 19, 2010 at 12:19 PM

Your Xaml code is using Click ="ButtonClick", and you are using QUIKsettings_Click. Make your xaml code Click="QUIKsettings_Click" that should fix it.

Nov 22, 2010 at 12:17 PM

I did it. But still not working

Coordinator
Nov 22, 2010 at 4:44 PM

Send me your project, i'll fix it for you. davinci {at} mail.ru

Nov 23, 2010 at 8:06 AM
Edited Nov 23, 2010 at 11:02 AM

My project is attached.

* davinci <notifications@codeplex.com> [22 Nov 2010 09:44:30 -0800]:
> From: davinci
>
> Send me your project, i'll fix it for you. davinci {at} mail.ru

Coordinator
Nov 23, 2010 at 9:44 AM

Your problem was incorrect x:Class of the window in XAML.
The fixed project has been sent to you.
Daniel 

Nov 23, 2010 at 11:03 AM
daVinci wrote:

Your problem was incorrect x:Class of the window in XAML.
The fixed project has been sent to you.
Daniel 

Thank you! Now it really works!