Situation:
In my WPF application, I have one tabControl including two tabItems, all the two tabitems are using xamzoombar, I move the xamzoombar position to some position, when I shift between the two tabItems, I found that the xamzoombar position was back to the initial position. I just want the xamzoombar be the position I moved, not the initial position.
Do I make myself clear? Thanks in advance.
Hello Charlie,
Thank you for your post. I have been looking into it and I can say that this behavior is expected, because when you shift between tabs the elements are unloaded and loaded and this is why the XamZoombar goes back to its initial position. I can suggest you define global variables and save the zoombar’s position. Also you can handle its Loaded event and set its position manually.
Hope this helps you.
Hello Stefan,
Thanks a lot!
And one more question, can I remove the left arrow and right arrow besides the xamZoombar ?
I can suggest you handle the XamZoombar’s Loaded event and add the following code in its handler:
Grid g = (Utilities.GetDescendantFromName(sender as DependencyObject, "HorizontalScrollbarElement") as Grid); if (g != null) { g.Children.RemoveAt(1); (g.Children[1] as FrameworkElement).Margin = new Thickness(10, 3, 10, 3); }
Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
I pasted your code in XamZoombar’s Loaded event, and it indeed solved my problem. But I find a problem, when I shift tabs between tab A which contains XamZoombar control and tab B, an exception(System.ArgumentOutOfRangeException) occured, the reason is when shift tabs back to tab A, XamZoombar’s Loaded event runs again, and g.Children[1] is out of index range. So I changed code to following:
Grid g = (Utilities.GetDescendantFromName(sender as DependencyObject, "HorizontalScrollbarElement") as Grid); if (g != null) { if (g.Children.Count == 3) { g.Children.RemoveAt(1); (g.Children[1] as FrameworkElement).Margin = new Thickness(10, 3, 10, 3); } }
It indeed solved my problem,but I don't think it's a good idea, do you have any better idea? Thanks~~~
I am glad that you resolved your issue. Also I have been looking into your code and I believe that for the moment it is the best approach for the functionality you want. If I think of a better one I will let you know.