WP8.1 AppBar size change - c#

How do I monitor AppBar's size changes? Specifically, I want to know when it gets opened(to show secondary commands and labels underneath icons).
There is a SizeChanged event, but it fires only before AppBar is shown on the screen.

CommandBar has Opened and Closed events. They are fired when SecondayCommands are shown/hidden.
Note that those events will be fired only if you have SecondayCommands in your AppBar.
As I've checked - Opening/Closing your AppBar doesn't change its ActualHeight. If you want to see its size changing you can play with ClosedDisplayMode - for example put this code in your AppBarButton.Click:
private void AppBarToggleButton_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine(BottomAppBar.ActualHeight.ToString());
if (BottomAppBar.ClosedDisplayMode == AppBarClosedDisplayMode.Compact)
BottomAppBar.ClosedDisplayMode = AppBarClosedDisplayMode.Minimal;
else BottomAppBar.ClosedDisplayMode = AppBarClosedDisplayMode.Compact;
}
The code above changes ActualHeight and thus SizeChanged event is being fired.

Related

How to detect when a ScrollViewer finishes scrolling?

BTW I'm using UWP in case it matters.
So I am using a ListView and all ListViews have a ScrollViewer attached to them (in default template) by default. The problem is that I cannot find an event (on the ListView itself or on its ScrollViewer) that triggers when the ListView finishes scrolling.
I used the scrollViewer.ChangeView() method to automatically scroll to the beginning of the ListView and it uses an animation to scroll to the top, so I think that has something to do with it because the ViewChanged event fires before the animation completes. If I am correct about that then there would have to be a way to determine if the animation is complete because I need to be alerted when the ListView is completely idle again, which is only when the scroll animation completes. Thanks.
You can wire up the scrollViewer's ViewChanged event, and check the IsIntermediate of the event argument.
private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
if (e.IsIntermediate)
{
System.Diagnostics.Debug.WriteLine("scroll ongoing");
}
else
{
System.Diagnostics.Debug.WriteLine("scroll finish");
}
}
This event is fired multiple times. When the scroll finishes, IsIntermediate is false.

C# Winform panel Shown event

Is there an event for panel that is equivalent to form event Shown?
I had a few couple of panel switching within a form which will never be closed.
However i couldn't find anything close to an event like Shown which is used in form.
The closes i had is Paint event. However i only wish to update the panel once every time it is shown.
Form.Shown is not raised every time the form is shown, rather it Occurs whenever the form is first displayed. This being said, there is no Panel.Shown event, and no event which is raised "whenever a panel is first displayed".
You can simulate this behavior with the Panel.Paint event, using a flag to keep track of whether it's been "shown" once before. This will make it behave similar to Form.Shown.
private bool panel1Painted = false;
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (!panel1Painted)
{
// do your shown stuff here
panel1Painted = true;
}
}
To keep in the spirit of Form.Shown, you may want to reset the flag if the Panel is reconstructed. This is not the same as shown.
You could listen on the VisibleChanged event and only act on when visibility = true.
https://msdn.microsoft.com/en-us/library/system.windows.forms.panel_events%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
You could also experiment with the Enter and Invalidated events to see if these give you the results you want.
Or if disabling the panel when leaving it is an option, you might be able to use the EnabledChanged event in your toolbox.

Control.Capture is always true?

I have created a Windows Forms application, but I get strange behaviour from the Capture property of a control.
On a blank form, with a single label called "label1" and the code
public Form1()
{
InitializeComponent();
label1.MouseDown += pictureBox1_MouseDown;
}
void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Debug.WriteLine(label1.Capture);
label1.Capture = !label1.Capture;
Debug.WriteLine(label1.Capture);
}
I observed, that the first WriteLine always says "True", the second one always says "False" when the button is clicked. Even when clicked multiple times.
The label never reacts to clicks outside its border, not even when I use label1.Capture = true instead.
Am I misunderstanding the expected behaviour of the "Capture" property? I expected the initial value to be false, and the label not to react to clicks outside, after the first click I expect the value to be true, and the label to react to all mouse clicks, even outside its borders.
In a MouseDown event, the Capture for the control always set to true initially. So normally if you perform a MouseDown and then without releasing mouse button move your mouse out of the control and then release mouse button, the MouseUp event of the control will be fired.
If you set Capture to false in MouseDown, then the mouse up event of your control will only fire if your mouse is over the control and if you move the mouse out of your control and then release mouse button, the MouseUp event of your control will not raise.
Also in MouseUp the capture will be released automatically.
For more information take a look at these resources:
WmMouseDown method source code
WmMouseUp method source code
CaptureInternal proprty source code
SetCapture documentations
ReleaseCapture documentations

ListView click event not triggered when clicking on empty areas

I have a ListView control on my form. I have set its display mode to LargeImageList. I need to handle the items inside this control. So I have written code for its click event. But I see now that this event is not triggered when I click in an empty area inside it.
How can I make my ListView aware of the clicks on its area regardless.
To capture mouse clicks on the "white space" around the ListView items, you will need to use the MouseDown/MouseUp events.
This will also capture clicks to the items as well.
I've used the Global Mouse Hook for similar issues. You can use it to detect Mouse Clicks anywhere on the screen, then just check the click was within the listview control bounds.
Grab the code from Global Mouse Key Hook
IKeyboardMouseEvents m_GolbalHook = Hook.GlobalEvents();
m_GolbalHook.MouseClick += m_GolbalHook_MouseClick;
private void m_GolbalHook_MouseClick(object sender, MouseEventArgs e)
{
if (listView.Bounds.Contains(e.Location)) && (e.Button == System.Windows.Forms.MouseButtons.Left))
{
//Do Stuff
}
}

SplitView.PaneClosed event is available but not for PaneOpened

According to the https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.splitview.paneclosed.aspx there is no PaneOpened event for the SplitView control, only PaneClosed event for the SplitView control that exists.
I have a Button control inside a SplitView pane that needs to change in size according whether the pane is opened or closed. So my plan is I will place a piece of code that will change the button size wider in the PaneOpened event, and restore it back to the small size in PaneClosed event. But it seems there is no PaneOpened event.
Any other way that I can achieve this?
Thanks to the new RegisterPropertyChangedCallback in UWP, you can now monitor property change events of any DependencyProperty, including native ones.
public SplitViewPage()
{
this.InitializeComponent();
this.splitView.RegisterPropertyChangedCallback(SplitView.IsPaneOpenProperty, IsPaneOpenPropertyChanged);
}
private void IsPaneOpenPropertyChanged(DependencyObject sender, DependencyProperty dp)
{
// put your logic here
}

Categories