I need my silverlight button to call a specific method, but my button doesn't have any click property. The Intellisense shows "clickmode" but no "click"
I'm definitely using the System.Windows.Controls.Button control
Here's my code for the xaml file
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Telerik_Windows_Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting" x:Class="..."
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Telerik_Windows_Controls:RadChart Name="radChart" Content="RadChart" Margin="78,47,0,0" d:LayoutOverrides="Width, Height"/>
</Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="8,8,0,0" VerticalAlignment="Top" Width="75"/>
</UserControl>
A WPF button has an "OnClick" event, or a "Command" property. You may find this link useful: WPF Commanding Overview
Silverlight's Button does have an event called Click, defined in ButtonBase, see the MSDN API documentation. So you might write XAML like:
<Button Content="Button" ... Click="My_Event_Handler"/>
However, have a look at Commanding as referenced by the other answer for the "nice" way to do things (Button's Command property).
Related
Image with Problem
This is a WPF application launched with debug of visual studio
I've a window, where show content
<Window x:Class="Test.All"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test"
mc:Ignorable="d"
Title="All" Height="450" Width="800">
<Grid>
</Grid>
and a user control, with the content to show in the window
<UserControl x:Class="Test.ShowContent"
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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Test"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Button x:Name="btnrand" Content="button" HorizontalAlignment="Left" Margin="300,69,0,0" VerticalAlignment="Top" Width="200" RenderTransformOrigin="0.473,0.477" Height="58" Click="btnrand_Click"/>
<Label x:Name="showblasph" Content="" HorizontalAlignment="Left" Margin="60,169,0,0" VerticalAlignment="Top" Height="163" Width="664" FontSize="24"/>
</Grid>
</UserControl>
With a WinForms application, I did not have that problem, but with wpf yes, any ideas?
The problem is the arrows at the top
You are accidentially using a NavigationWindow instead of a Window. A navigation window has built-in browser-like controls. These controls are not shown in the Visual Studio designer, but at runtime. The black bar at the top are the XAML debugging tools, that you can enable or disable in debug mode.
A navigation window is used automatically, if you specify a UserControl resource as StartupUri. What type of window is used or created depending on the startup URI is documented here.
Types that display a NavigationWindow when set as StartupUri resource:
NavigationWindow
Page
UserControl
FlowDocument
PageFunction<T>
Therefore, you have to set a Window as StartupUri and set its Content to your UserControl.
I am using syncfusion: menuItemAdv control for showing a hierarchical menu items for an applications.
OnMouseOver or OnMouseClicked(ExpandMode Property)it shows the sub items on mouse hover a menu items. But It doesn't disappear that list on mouse leave. However, If I click anywhere else on the windows(lost focus probably),then it cleans the sub menu item.
So, Instead of clearing the sub menu items on lost focus. I want to do that on mouse leave as user might open any other application without causing lost focus event and might get confused. So, I want to clear the item list on mouse leave.
I know, I can write a behavior and can hook it's on mouse leave event but I don't know how to clean that list. As there is no method exposed from this library. tempering with item source might screw something.
Any help is appreciated.
xaml is as following
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:MainWindowVM></local:MainWindowVM>
</Window.DataContext>
<Grid>
<syncfusion:MenuAdv Width="300" Height="40" ItemsSource="{Binding League}" ExpandMode="ExpandOnMouseOver">
<syncfusion:MenuAdv.ItemTemplate >
<HierarchicalDataTemplate DataType="local:MenuList" ItemsSource="{Binding Teams}" >
<StackPanel Orientation="Vertical" VerticalAlignment="Top" >
<Label Content="{Binding Name}" Height="Auto" FontFamily="Arial" FontSize="12" VerticalAlignment="Top" Margin="0,3,0,0" VerticalContentAlignment="Center"/>
</StackPanel>
</HierarchicalDataTemplate>
</syncfusion:MenuAdv.ItemTemplate>
</syncfusion:MenuAdv>
</Grid>
</Window>
We have checked the reported behavior and considered this as bug. The fix for this bug will be included in our volume 3 SP2 release which is scheduled to be rolled out by end of September.
Regards,
Durga S.
When I try adding more than one element to my WPF form in the editor in VC#2013, the previous element disappears. In the end, I can't have more than one item in the form. I've already written some code so I'd prefer not starting again from scratch. The form has nothing special besides being borderless, fullscreen and starting maximized.
This is the XAML code for the form right now:
<Window x:Class="queue_bigscreen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="1080" Width="1920" WindowStyle="None" ResizeMode="NoResize" WindowState="Maximized" Background="#FF9EA7CD">
<Label x:Name="nowServingLabel" Content="0" Margin="42,56,1160,131" Foreground="White" Height="893" FontSize="700" HorizontalContentAlignment="Center">
<Label.Effect>
<DropShadowEffect ShadowDepth="13"/>
</Label.Effect>
</Label>
</Window>
And this is what I get after I select a textbox and try adding it to the form:
<Window x:Class="queue_bigscreen.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="1080" Width="1920" WindowStyle="None" ResizeMode="NoResize" WindowState="Maximized" Background="#FF9EA7CD">
<TextBlock HorizontalAlignment="Left" Margin="1332,382,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
As you can see, the label disappears, and the textbox I added in turn disappears if I try adding something else. Am I doing something wrong or is it a known bug?
You need to put the items in a container. Window can only have a single root element, so to get multiple elements on the form, you need to have an element that allows children.
The closest to Windows Forms Form would be Grid. You can then put controls in that, with absolute and relative positioning. It's also the default, so I assume you accidentally deleted it from your XAML (or by being too aggressive with pressing delete in the designer).
Example form with a label and a textbox:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Label Content="Label" HorizontalAlignment="Left" Margin="23,30,0,0" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="66,32,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
</Window>
I'm used to create my forms with the designer, and modifying the XAML manually only when needed.
Even though the extended toolkit is a fantastic library, it still lacks integration with Visual Studio's designer. Can, by any mean, the toolkit's controls be displayed in the designer (not the toolbox), like standard controls? And if not, is there an explanation?
For now, the toolkit's controls are just blank and unselectable with simple clicks.
NOTE: It seems that the issue happens with container components (like BusyIndicator and Wizard/WizardPage) only.
EDIT: Here's some of my XAML. With this, I can see the wizard's first page, but no obvious way to see the others. If I put my Wizard in a BusyIndicator, can't see a thing at all.
<Window x:Class="MyProgram.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyProgram"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="My Program" Height="477" Width="688" MinWidth="688" MinHeight="478">
<xctk:Wizard x:Name="wizard" FinishButtonClosesWindow="True" Next="wizard_Next">
<xctk:WizardPage Name="Intro_Page" Title="ABC" Description="abc" NextPage="{Binding ElementName=Second_Page}" Enter="disallowNext">
<xctk:WizardPage.Content>
<Grid>
<Label Content="abc" HorizontalAlignment="Center" Margin="0,54,0,87" Name="intro_lbl" VerticalAlignment="Center" Grid.Column="1" Padding="5" HorizontalContentAlignment="Center" Height="28" IsEnabled="False" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Second_Page" Title="DFG" Description="dfg" NextPage="{Binding ElementName=Last_Page}">
<xctk:WizardPage.Content>
<Grid Name="grid">
<TextBox Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Name="txt_second" VerticalAlignment="Center" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Last_Page" PageType="Interior"
Title="Last Page"
Description="This is the last page in the process"
CanFinish="True" />
</xctk:Wizard>
</Window>
I know this answer comes late, but yesterday I was stumbling myself over this problem and maybe it is useful for others who land here.
I solved it by creating an own control derived from WizardPage.
Just Create a new UserControl, include the Xceed.Wpf.Toolkit namespace and change the Type from UserControl to xctk:WizardPage in the xaml file as well as in the code-behind file.
<xctk:WizardPage x:Class="WizardTest.MyWizardPage"
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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:WizardTest"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock>Hello World!</TextBlock>
</Grid>
</xctk:WizardPage>
Now you can create your UI using the VisualStudio Designer.
To place your page in the wizard, simply put an object of you derived page into its items:
<xctk:Wizard>
<local:MyWizardPage Title="My Wizard Page"/>
</xctk:Wizard>
You can use Bindungs in your costum page out of the box because DataContext of the MyWizardPage object is set automatically to the wizards DataContext (which inherits from the Window DataContext if not explicitly given)
I am trying to simply navigate from one .xaml page to another. I realize that the navigation template is built for this but I do not want the mainpage header / content below feel that it brings. Using a blank Silverlight application (C#) I want to move from Page1.xaml to Page2.xaml using a hyperlink button.
On Page1.xaml I have a hyperlink button like this:
<HyperlinkButton Content="Preview Report" Height="24" HorizontalAlignment="Stretch" Margin="98,296,377,21" Name="hyperlinkButton1" NavigateUri="/Page2.xaml" />
this doesn't seem to work. Please help
You will need a navigation frame in your MainPage in order to support this. Start with blank Silverlight Application.
Modify MainPage.xaml to look like:-
<UserControl x:Class="StackoverflowSpikes.NavPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<navigation:Frame Source="/Page1.xaml" />
</Grid>
</UserControl>
Add two or more Navigation Page's to your project. Now you can add HyperLinkButton elements to them.