I'm looking for free splitbutton control for silverlight.
I've seen this blog however I cannot download it. Its blocked in my firewall.
Do you know any free splitbutton for silverlight?
Thank you
It is available for free in the Silverlight Toolkit.
Download the latest Silverlight Toolkit from CodePlex.
http://silverlight.codeplex.com/
Download the SplitButton Samples and Project. You may use the SplitButton project to compile your own version of the SplitButton.dll or use the Sample programs to study. (optional)
http://dlaa.me/Samples/SplitButton/SplitButton.zip
Add references (right click References) to the Silverlight toolkit and the SplitButton.dll in your Silverlight project.
SplitButton.dll
System.Windows.Controls.Input.Toolkit.dll
Add both namespaces to your XAML, for the Silverlight toolkit and the new SplitButton.
xmlns:splitButton="clr-namespace:Delay;assembly=SLTKSplitButton"
xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
Add the Split Button code. This makes one button that drops to three options.
<splitButton:SplitButton x:Name='Button1' Content="Open" Click="Button1_Clicked">
<splitButton:SplitButton.ButtonMenuItemsSource>
<toolkit:MenuItem Header="Open" Click="Button1_Clicked" />
<toolkit:MenuItem Header="Open read-only" Click="Button1_ClickedRO" />
<toolkit:MenuItem Header="Open as copy" Click="Button1_ClickedAC" />
</splitButton:SplitButton.ButtonMenuItemsSource>
</splitButton:SplitButton>
Add Csharp code for click handlers for main button click or any of the three sub-option clicks.
private void Button1_Clicked(object sender, RoutedEventArgs e)
{
MessageBox.Show("Opening document normally...");
}
private void Button1_ClickedRO(object sender, RoutedEventArgs e)
{
MessageBox.Show("Opening document read-only...");
}
private void Button1_ClickedAC(object sender, RoutedEventArgs e)
{
MessageBox.Show("Opening document as a copy...");
}
Give thanks to David Anson, a Microsoft developer who works with the Silverlight, Windows Phone, and WPF platforms. Twitter: #DavidAns
Related
We have a CRM Add-in for Microsoft Outlook, which displays a custom task pane which has a WinForm control inside a WPF form/control as one of its functionalities. But, since after Version 1812 and the latest update to Office 365 pro plus installations, in some of the client machines we have been facing the following error/exceptions and form doesn't show or load:
System.InvalidOperationException: Hosted HWND must be a child window
of the specified parent. at
System.Windows.Interop.HwndHost.BuildWindow(HandleRef hwndParent)
at System.Windows.Interop.HwndHost.BuildOrReparentWindow() at
System.Windows.Interop.HwndHost.OnSourceChanged(Object sender,
SourceChangedEventArgs e) at
System.Windows.SourceChangedEventArgs.InvokeEventHandler(Delegate
genericHandler, Object genericTarget) at
System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object
target) at
System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,
RoutedEventArgs routedEventArgs) at
System.Windows.EventRoute.InvokeHandlersImpl(Object source,
RoutedEventArgs args, Boolean reRaised) at
System.Windows.UIElement.RaiseEventImpl(DependencyObject sender,
RoutedEventArgs args) at
System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) at
System.Windows.PresentationSource.UpdateSourceOfElement(DependencyObject
doTarget, DependencyObject doAncestor, DependencyObject doOldParent)
at
System.Windows.PresentationSource.OnVisualAncestorChanged(DependencyObject
uie, AncestorChangedEventArgs e) at
System.Windows.UIElement.OnVisualAncestorChanged(Object sender,
AncestorChangedEventArgs e) at
System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject
e, AncestorChangedEventArgs args) at
System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject
oldParent) at System.Windows.Media.Visual.AddVisualChild(Visual
child) at System.Windows.Media.VisualCollection.ConnectChild(Int32
index, Visual value) at
System.Windows.Media.VisualCollection.Add(Visual visual) at
System.Windows.Controls.UIElementCollection.AddInternal(UIElement
element) at System.Windows.Controls.UIElementCollection.Add(UIElement
element)
Basically, the code fails while embedding and displaying the WPF form. The exact code snippet causing the issue is as follows:
public void DisplayForm(System.Windows.Forms.Control form)
{
// Adapt WinForm Form Control to WPF
System.Windows.Forms.Integration.WindowsFormsHost wfh = new System.Windows.Forms.Integration.WindowsFormsHost();
wfh.Child = form;
wfh.Margin = new Thickness(0);
// Display WPF Form
DisplayForm(wfh);
}
// Embed a WPF Control
public void DisplayForm(UIElement form)
{
HostPanel.Children.Clear();
//***Below line throws an exception***
HostPanel.Children.Add(form);
}
In the above code,
HostPanel: System.Windows.Controls.Grid
Children: UIElementCollection Panel
Also, the HostPanel or the grid has been used/placed in the XAML like below :
<Grid>
<!-- Form Panel -->
<Grid Name="HostPanel" Margin="0,50,0,0">
</Grid>
And, in the XAML code partial class:
We are assigning the Winform control as a child of the WPF.
Then, we are trying to add the WPF form/UIElement in the UIElementCollection Panel of the grid control.
It is really difficult to narrow down to the exact root cause of the issue when everything was working as expected and just after pushing the updates to the Microsoft Office, the errors/exceptions are being seen.
Any help or pointers towards resolving the issue will be greatly appreciated.
Thanks!
**
Update
**
This issue seems to be due to Microsoft introduced Office support for High DPI
And the issue could be fixed inside Outlook by selecting "Optimize for compatibility" in Display Settings on the bottom status bar or in User Interface options under General Outlook options:
Image for the setting/configuration
However, is there a way to make the above-mentioned code DPI aware and to get the form controls rendered without any issue?
Also, from this MSDN Article, I learn that it might not be possible as child parented to Office window cannot respond to DPI scaling. But, any further inputs on the same would be highly appreciated.
Thanks.
I am developing a windows 8.1 store app. I have a SearchBox control in my app. I want to set focus on it when pointer is pressed on it.
I have tried the following code but it is not working
private void SearchBox_FullView_PointerPressed(object sender, PointerRoutedEventArgs e)
{
SearchBox_FullView.Focus(FocusState.Pointer);
}
How can I solve this problem?
Try this:
private void SearchBox_FullView_PointerPressed(object sender, PointerRoutedEventArgs e)
{
SearchBox_FullView.Focus(FocusState.Programmatic);
}
My problem is solved the problem was in XAML hierarchy that was
<Grid>
<Button/>
<SearchBox/>
<Hub/>
</Grid>
As Hub covers the whole window the Searchbox was visible but not focusable because of the Hub.
I just changed the hierarchy and put the Searchbox after the Hub and it became focusable. And by putting it after the Hub, there was no need for a button left to remove default focus from the SearchBox.
I am writing a WPF control which is hosted in an Word VSTO AddIn (WinForms). Now I have a problem with the mouse click events on a context menu.
If I click on a context menu item on the left half (the part over the WinForms app), the click goes directly to the WinForms app and my context menu does not receive the event.
If I click the right half of the item (part over the WPF form), everything works as expected.
Can someone out there help me solve this issue?
The answer from the inactive blog is:
Declare a class level dispatcher frame object
System.Windows.Threading.DispatcherFrame _frame;
Subscribe to the GotFocusEvent and LostFocusEvent for the menu:
_menu.AddHandler(System.Windows.UIElement.GotFocusEvent,new RoutedEventHandler(OnGotFocusEvent));
_menu.AddHandler(System.Windows.UIElement.LostFocusEvent, new RoutedEventHandler(OnLostFocusEvent));
Below is the implementation for the event procedures for the GotFocusEvent and LostFocusEvent:
private void OnGotFocusEvent(object sender, RoutedEventArgs e)
{
if (LogicalTreeHelper.GetParent((DependencyObject)e.OriginalSource) == _menu)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal (DispatcherOperationCallback)delegate(object unused)
{
_frame = new DispatcherFrame();
Dispatcher.PushFrame(_frame);
return null;
}, null);
}
}
private void OnLostFocusEvent(object sender, RoutedEventArgs e)
{
if (LogicalTreeHelper.GetParent((DependencyObject)e.OriginalSource) == _menu)
{
_frame.Continue = false;
}
}
In my case, the if statements weren't needed and I subscribed to the events like this
<EventSetter Event="GotFocus" Handler="contextMenu_GotFocus" />
<EventSetter Event="LostFocus" Handler="contextMenu_LostFocus" />
After some deep research I stumbled upon the following bug:
https://web.archive.org/web/20101211205036/http://connect.microsoft.com:80/VisualStudio/feedback/details/432998/excel-2007-vsto-custom-task-pane-with-wpf-context-menu-has-focus-problems
It's for Excel 2007, but is still valid for other Office products (2007, 2010). I managed to fix my issue using the method described here:
https://web.archive.org/web/20151231010333/http://blogs.msdn.com/b/vsod/archive/2009/12/16/excel-2007-wpf-events-are-not-fired-for-items-that-overlap-excel-ui-for-wpf-context-menus.aspx
I want to navigate to new page on the click event of Next button. Suppose my current page is "FirstTestPage.xaml" and want to go on the page "SecondTestPage.xaml" on click on nextButton_Click Event
private void RadButton_Click(object sender, RoutedEventArgs e)
{
///CODE HERE
}
And also want the back button which transfer me to FirstTestPage.xaml.
Thank You
Please see my answer to the question: Making a Wizard in Silverlight + Xaml
to quote it: "I would suggest looking into the Silverlight Navigation Framework. It allows you to use "urls" to navigate between "pages" (which are your XAML user controls). It also also users to use the back and forth buttons in the browser, which may or may not be something you want to allow.
There is a VS 2010 template when you choose New Project, Silverlight, "Silverlight Navigation Application" that will help get you started."
You can also use a border or panel in the Xaml and change the content of that. Here's an example using border.
XAML
<Grid>
<Border x:Name="contentBorder" />
</Grid>
Code Behind:
private void RadButton_Click(object sender, RoutedEventArgs e)
{
this.contentBorder.Child = new SecondTestPage();
}
If you want to get fancy and have the Telerik controls (which I assume from your RadButton example) check out their transition control: http://demos.telerik.com/silverlight/#TransitionControl/FirstLook
I am developing an addin to Microsoft Outlook.
The following code works fine if I use an winforms UserControl:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
var testControlView1 = new UserControl1();
var MyCustomPane = this.CustomTaskPanes.Add(testControlView, "Hello");
}
How can I do it with a WPF UserControl, instead? Does anybody know how I would achieve similar functionality?
As far as I can tell the CustomTaskPanes only allow Winforms Controls to be added to it.
Just found a solution,
https://stevepietrekweblog.wordpress.com/2009/03/24/vsto-display-wpf-user-control-in-custom-task-pane/
This update was just to update the link.