Avalon Dock Auto Hide problems on load - wpf

I am having a problem with Avalon Docking where my second panel that's docked at the bottom and set to AutoHide.
When UI runs the pane loads as Docked/Visible by default. I would like to have it hidden/minimized.
<ad:DockingManager>
<ad:ResizingPanel Orientation="Vertical">
<ad:DocumentPane>
<ad:DocumentContent>
<... data grid that fills the view>
</ad:DocumentContent>
<ad:DocumentPane>
<ad:DockablePane>
<ad:DockableContent Title="output" DockableStyle="AutoHide" IsCloseable="False">
<...some control>
I have tried various "hacks" suggested on Avalon forums, where OnLoad, you can
outputDockablePane.ToggleAutoHide();
and that works, meaning, when UI is loaded the pane is hidden. However, once you toggle auto hide in .cs code, clicking on the dock header at runtime to make the pane visible/float stops working. So you have to hook up DockingMananger.OnMouseUp() and parse through a couple of boolean states and manually call ToggleAutoHide() - I guess only on the time. Seems like a hack to me.
Here's what I am doing for now, till I find a proper and clean solution:
private void OnDockManagerLoaded(object sender, RoutedEventArgs e)
{
if(_firstTimeLoad && !_isDataGridLoaded)
{
outputDockablePane.ToggleAutoHide();
_forcedToAutoHide = true;
}
}
private void OnDockingManagerMouseUp(object sender, MouseButtonEventArgs e)
{
if (_forcedToAutoHide)
{
_forcedToAutoHide = false;
outputDockableContent.Activate();
outputDockablePane.ToggleAutoHide();
}
}
Is there a setting/property that I am totally missing, or/and a better way?

4 Years still Avalon Docking has the same issue .While I haven't found a proper solution yet , I have tried to refine you workaround logic.
private void OnDockingManagerMouseUp(object sender, MouseButtonEventArgs e)
{
if (outputDockableContent.IsAutoHidden)
{
outputDockableContent.IsActive = false;
}
}

Related

Wpf not all windows are maximized from taskbar

I have three windows. FirstWindow, SecondWindow and ThirdWindow. FirstWindow has button and click on this button opens the SecondWindow. Analogously, SecondWindow has button and click on this button opens the ThirdWindow. Owner property of the SecondWindow is set as FirstWindow and Owner property of the ThirdWindow is set as SecondWindow. The scenario discribing problem:
Open all windows in a row. It will be looked like this:
Then minimize all windows by click on corresponding icon at top right corner of ThirdWindow.
If you will try to maximize all windows by clicking on FirstLevelWindow or ThirdLevelWinow in taskbar - all will be ok, three windows will be maximized. But if you will click on SecondWindow you will see this:
How can I fix it, or it is just WPF bug? I can give archived expample project if it helps.
UPDATE
Minimize window - click "_" icon, left icon in iconbar of the window. All windows are modal, i.e it opens with ShowDialog() method, not with Show() method. So if you minimize third window - all the windows will be minimized.
Here the code if you don't want download project by link:
FirstWindow XAML:
<Button Click="OpenChildWindow"
Content="ChildWindow"/>
FirstWindow .cs:
private void OpenChildWindow(Object sender, RoutedEventArgs e)
{
var window = new SecondLevelWindow();
window.Owner = this;
window.ShowDialog();
}
SecondWindow XAML:
<Button Click="OpenChildWindow"
Content="ChildWindow"/>
SecondWindow .cs:
private void OpenChildWindow(Object sender, RoutedEventArgs e)
{
var window = new ThirdLevelWindow();
window.Owner = this;
window.ShowDialog();
}
ThirdWindow is empty window without any content.
Here link to example project
I've just found, that bug is not reproduced if property ResizeMode of ThirdWindow is set to "NoResize". Mb it will be usefull information.
Well, I admit I have no idea what is going on. Did you try to add a fourth window? This become even stranger: the second window bring back the third, but the fourth is still not back.
Anyway, If I had to manage this problem, I would keep a reference of my childWindow in each parent Window. This way on any interesting event (like activate on the second window in your example) I could manage the state of my child as required (WindowState.Normal in your case).
It could be something like that: in xaml of secondWindow:
Activated="SecondLevelWindow_OnActivated"
And then in code behind:
private ThirdLevelWindow _window;
public SecondLevelWindow()
{
InitializeComponent();
}
private void OpenChildWindow(Object sender, RoutedEventArgs e)
{
_window = new ThirdLevelWindow ();
_window.Owner = this;
_window.ShowDialog();
}
public void SecondLevelWindow_OnActivated(object sender, EventArgs e)
{
if (_window != null)
{
_window.WindowState = WindowState.Normal;
}
}
This is a start, but you could also inspect your current state to define the state of your child.
Hope it helps.

Touch Scrolling ScrollViewer in WPF App with RealTimeStylus Disabled

We are working on a WPF 4.5 application that will be run on Windows 8 computers with touchscreen monitors.
We have disabled support for the RealTimeStylus following the directions on the MSDN, since we have some views that need multitouch support through WM_TOUCH.
The problem is that disabling the RealTimeStylus support seems to also disable the user's ability to scroll a ScrollViewer using touch - normally the user can pan around ScrollViewers with their fingers, but if RealTimeStylus support is disabled, it does not seem possible to do this. The ScrollViewer's PanningMode is set to "Both".
Is it possible to combine these things in a WPF application, or are they mutually exclusive?
Another option is to add arrow buttons around the content. We've used this to great effect on a touch screen kiosk. It's a bit more work, but could be made into a custom control. The only code I have supports vertical scrolling.
It should be easy enough to add horizontal scrolling as well. In the code below, there are two buttons, called Less and More above and below the scroller.
double Epsilon = .001;
private void Scroller_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
if ( Scroller.ScrollableHeight > 0 ) {
Less.Visibility = Math.Abs(Scroller.VerticalOffset - 0) > Epsilon ? Visibility.Visible : Visibility.Hidden;
More.Visibility = Scroller.VerticalOffset + Scroller.ViewportHeight < Scroller.ExtentHeight ? Visibility.Visible : Visibility.Hidden;
} else {
Less.Visibility = More.Visibility = Visibility.Hidden;
}
if (Scroller.ExtentHeight / Scroller.ViewportHeight > 2)
{
SearchPanel.Visibility = Visibility.Visible;
}
}
private void Less_Click(object sender, RoutedEventArgs e)
{
Sounds.Click();
Scroller.PageUp();
}
private void More_Click(object sender, RoutedEventArgs e)
{
Sounds.Click();
Scroller.PageDown();
}
Can you try SurfaceScrollViewer instead of normal ScrollViewer.
SurfaceScrollViewer

Button click event not responding after collapsing parent

I have a UserControl with a number of StackPanel's. I like to hide specific panels depending on the user action. A StackPanel which is visible on startup gives me a number of working buttons. The buttons have click events in the code behind file. After collapsing the panel and then making it visible again the buttons no longer work. Here is a part of my UserControl:
<StackPanel x:Name="buttonPanel" Orientation="Horizontal">
<Button x:Name="ReMindNodeNotes" Content=""
FontFamily="Segoe UI Symbol" FontSize="14" Foreground="#FF292323"
HorizontalAlignment="Left" BorderThickness="1" Padding="0"
UseLayoutRounding="True" Click="NoteClicked" />
<Button x:Name="ReMindNodeRemove" Content=""
FontFamily="Segoe UI Symbol" FontSize="14" Foreground="#FF292323"
HorizontalAlignment="Left" BorderThickness="1" Padding="0"
UseLayoutRounding="True" Click="RemoveClicked" />
</StackPanel>
And here is the code (for now just some text):
private void NoteClicked(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("NoteClicked...");
}
private void RemoveClicked(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("RemoveClicked...");
}
I have been looking for a solution the last two days. No luck so far. Who can help...?
THX Peter
Follow up 1...
Here is the code for collapsing the panel:
private void MoreClicked(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine(this.nodeName);
this.buttonPanel.Visibility =
this.buttonPanel.Visibility ==
Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}
It works if the buttonPanel has focus. If the focus is on another panel it does not. Furthermore, what I probably should have mentioned... is that users can create multiple instances of the user control.
THX
Follow up 2...
I continue working on a solution of course... ;-) and I found a solution, which however is not the solution I want. Let me explain.
Users can interactively create multiple instances of the user control mentioned before. When a new instance is created, that instance gets focus. Now every instance has its own set of buttons which are on a stackpanel. When the focus goes to another instance I want the panel of the previous instance to collapse. The focus should then be set to the new (or selected existing) instance.
When I do this manually, it works! When I try to achieve this through the GotFocus and LostFocus events however, it does not. Here is the code for the manual solution (which works):
private void MoreClicked(object sender, RoutedEventArgs e)
{
this.buttonPanel.Visibility =
this.buttonPanel.Visibility ==
Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}
Here are the LostFocus and GotFocus events:
private void NodeGotFocus(object sender, RoutedEventArgs e)
{
this.buttonPanel.Visibility = Visibility.Visible;
}
private void NodeLostFocus(object sender, RoutedEventArgs e)
{
this.buttonPanel.Visibility = Visibility.Collapsed;
}
I really appreciate your help! THX again...
Thanks for your sample morincer. The problem however is a little more complex. Let me try to explain the solution which I found after some more research. Maybe other developers can benefit from it as well.
I added the GotFocus and LostFocus events to my userconctrol. If I click somewhere inside the usercontrol the focus changes every time. Strange as these events are only defined on the usercontrol itself and not it's children. I have several buttons and a textbox inside the usercontrol and when I for example click on one of the buttons of the usercontrol that has focus the LostFocus and GotFocus events are fired for usercontrol anyway.
The most important event for me in this case is the LostFocus event. When the usercontrol looses focus - for example to another control - I want the button panel to disappear. Since the LostFocus event fires every time a object inside the usercontrol is touched, I cannot distinguish between the situation in which I want to hide and show the buttons.
I got a little closer to a solution by changing the LostFocus event as follows:
private void LostFocus(object sender, RoutedEventArgs e)
{
Object fo = FocusManager.GetFocusedElement();
if (fo.GetType().ToString().Contains("TextBox") ||
fo.GetType().ToString().Contains("ScrollViewer"))
{
this.buttonPanel.Visibility = Visibility.Collapsed;
}
}
This covers most of the situations. When the cursor is positioned in the TextBox the button panel is closed. The button panel is also closed when the user clicks on the background. This seems to be a ScrollViewer (found through debugging the code). Can anyone explain this...?
The situation which is not covered however, is when a user clicks on another usercontrol. It does of course when the user clicks on the TextBox (see the code) but not when the user clicks on a button. I tried to compare sender and FocusManager.GetFocusedElement(). Problem is that the sender returns the usercontrol (which is what I am looking for) but the FocusManager.GetFocusedElement() returns the button that was pressed. Now I could ask for it's parent which is a border then ask for the borders parent which is a stack panel and so on until I arrive at the usercontrol. A code behind file however was introduced with the idea to split design and logic while this solution would tie them together again. If I would change the XAML I would have to change the logic as well. Doesn't seem to be the right solution to me.
I found a solotion by giving every usercontrol a unique name in the constructor. I then give all the buttons unique names as well (I don't use them in my code anyway) starting with the name of the usercontrol. This then gives me the possibility to compare names at runtime and determine whether the focus has changed to another instance of the usercontrol. Here is the code:
private void NodeLostFocus(object sender, RoutedEventArgs e)
{
Object fo = FocusManager.GetFocusedElement();
if (fo.GetType().ToString().Contains("ScrollViewer"))
{
this.buttonPanel.Visibility = Visibility.Collapsed;
}
else if (fo.GetType().ToString().Contains("TextBox"))
{
if (!((TextBox)fo).Name.Contains(this.nodeName))
{
this.buttonPanel.Visibility = Visibility.Collapsed;
}
}
else if (fo.GetType().ToString().Contains("Button"))
{
if (!((Button)fo).Name.Contains(this.nodeName))
{
this.buttonPanel.Visibility = Visibility.Collapsed;
}
}
}
Now this works! But…I don't like the solution. I am depending on names instead of a good architecture. Does anyone hove an idea how to compare the actual sender with the usercontrol that is the parent of the button pressed (FocusManager.GetFocusedElement())? Or any other solution that relies on good programming?
THX again

Silverlight UserControl with rectangle as a button

I have a problem using custom made UserControl in Silverlight Page.
The UserControl is generally a rectangle containing a smaller rectangle inside.
I want to use the UControl in a Silverlight MainSite.
i've implemented a method on mouse button down for a smaller rectangle called in here Button1:
public void Button1_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MessageBox.Show("Hello");
}
How can i use it from a MainSite? From there I can only implement a method like:
private void ImportedControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
firstLeaf.Button1_MouseLeftButtonDown(sender, e);
}
I can not implement a method for Button1.
How can i mek this Work?
HELP:)
I am still not sure I understand the question, but let me take a swing at an answer. Why don't you use a real Button and just template it with a rectangle? This way you get all the benefits of actually having a button while having it look like a rectangle, including the Click event.
Here is a post Scott Guthrie did on control templating with a button.

How to set focus on TextBox in Silverlight 4 out-of-browser popup

I have a simple ChildWindow popup in Silverlight 4 (beta).
Important: This is an out-of-browser application.
i want to auto set focus on a TextBox control when the window opens.
I've tried a couple things :
The following code doesn't seem to do anything. I don't think the control is ready to be focussed after 'Loading'.
private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
textBox1.Focus();
}
This works, but its klunky.
private void ChildWindow_GotFocus(object sender, RoutedEventArgs e)
{
if (_firstTime == true) {
textBox1.Focus();
_firstTime = false;
}
}
Isn't there a better way? I always had to do horrible things like this in WinForms but was hoping not to have to anymore.
Note: This similar question is for in browser only. It suggests calling System.Windows.Browser.HtmlPage.Plugin.Focus(); which doesn't work and in fact gives an error when running on Silverlight 4 beta out-of-browser.
I was having the same problem in SilverLight 4 (OOB) and I noticed that the tab sequence would set focus to a control that i could not see. What appears to be happening is the focus is being set to your control (first one in the tab sequence) and then for some reason the focus moves to the ContentControl (name ="content"), which (i think) is the parent of the child window.
ContentControl by default has IsTabStop=true.
see....
Why would I want IsTabStop set to true on a ContentControl?
To set the ContentControl.IsTabStop = false for all ContentControls in your app, add this to your styles.xaml.
<Style TargetType="ContentControl" >
<Setter Property="IsTabStop" Value="false"/>
</Style>
The same issue happens with the tab sequence on the MainPage. This style will also fix this.
You are on the right track. You need to handle for two test cases:
1. Setting the focus in the browser.
2. Setting the focus out of the browser.
Your code you that you showed in the Loaded event will work perfectly fine out of the browser. All that is necessary is to refactor it to handle both cases:
private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
{
if (App.current.IsRunningOutOfBrowser)
{
textBox1.Focus();
}
else
{
System.Windows.Browser.HtmlPage.Plugin.Focus();
textBox1.Focus();
}
}
That should do the trick for you.
Thanks for all the posts but after doing a little research the below thing work for me
in Xamal:
<TextBox VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Arial" FontSize="12" Height="25" Width="200" Margin="38,50,0,0" Name="txtUserName" Text="{Binding LoginInfo.UserName,Mode=TwoWay, NotifyOnValidationError=True}" IsTabStop="True" TabIndex="1" ></TextBox>
// Initialiazing Main Part View Model
/// </summary>
/// <param name="mainPartViewModel"></param>
public ChildWindowLoginControl(MainPartViewModel mainPartViewModel)
{
InitializeComponent();
this.DataContext = mainPartViewModel;
System.Windows.Browser.HtmlPage.Plugin.Focus();
this.GotFocus += (s, e) => { txtUserName.Focus(); };
}
I had to use your GotFocus way for Silverlight 3 application written in IronPython when I wanted to set focus in ChildWindow.
I use:
protected override void OnOpened()
{
base.OnOpened();
textBox1.Focus();
}
Thanks for all the post, but i have find the work done through following.
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
if (App.Current.IsRunningOutOfBrowser)
{
txtSalesOrderNo.Focus();
}
else
{
System.Windows.Browser.HtmlPage.Plugin.Focus();
txtSalesOrderNo.Focus();
}
}

Resources