How can I prevent an Office Custom Task Pane for resizing, so that it's only and always have the dimensions and can't be closing with the "close" button.
myCustomTaskPane.Height = 500;
myCustomTaskPane.Width = 500;
As far as the resize, just monitor your task pane's resize event and reset the size. However you might consider +why+ you'd want to do that. If there's a minimum necessary size for your taskpane, it might make more sense to restrict the minimum. and if the contents are resizable, maybe they should be.
You might also override the OnLayout method. That will often work better.
For the Close button, I think you'd want to intercept the "VisibleChanged" event and make the pane visible if it's been hidden. As I recall, taskpanes are not actually "closed" per se, but just set invisible.
Where _tp is a reference to your task pane (not the CustomTaskPane container), _ctp is the CustomTaskPane container, iw is the InspectorWrapperDictionary:
void _tpvals_VisibleChanged(object sender, System.EventArgs e)
{
_tp.tmr.Start();
}
And, in your task pane code:
public Timer tmr;
public taskpane()
{
InitializeComponent();
tmr = new Timer() { Interval = 500 };
tmr.Tick += new EventHandler(tmr_Tick);
tmr.Enabled = true;
tmr.Stop();
}
void tmr_Tick(object sender, EventArgs e)
{
if (iw == null)
setVars();
if (_tp.lv_AttachmentList.Items.Count > 0)
_ctp.Visible = true;
tmr.Stop();
}
setvars() is a command to pull in the proper iw and set the references to _tp and _ctp
I find a Solution for this One :
void NormalizeSize(object sender, EventArgs e)
{
if (this.taskPane.Height > 558 || this.taskPane.Width > 718)
{
this.taskPane.Height = 558;
this.taskPane.Width = 718;
}
else{
this.taskPane.Width = 718;
this.taskPane.Height = 558;
}
}
For the "Must not be closed"-Part of the problem you can maybe use this one instead of a timer:
private void myCustomTaskPane_VisibleChanged(object sender, EventArgs e)
{
if (!myCustomTaskPane.Visible)
{
//Start new thread to make the CTP visible again since changing the
//visibility directly in this event handler is prohibited by Excel.
new Thread(() =>
{
myCustomTaskPane.Visible = true;
}).Start();
}
}
Hope it helps,
Jörg
Related
I have to show a web browser inside a scroll viewer in windows phone application, with these requirements :
Web browser height should be adjusted based on its content.
Web browser scrolling should be disabled, ( when user scrolls within web browser, scrolling of scroll viewer should take place )
Web browser can do pinch-zoom and navigate to links inside its content.
How can I implement that? Any links or samples is greatly appreciated.
I'm using code like this. Attach events to the Border element in the Browser control tree (I'm using Linq to Visual Tree - http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/).
Browser.Loaded +=
(s,e)=>
{
var border = Browser.Descendants<Border>().Last() as Border;
if (border != null)
{
border.ManipulationDelta += BorderManipulationDelta;
border.ManipulationCompleted += BorderManipulationCompleted;
border.DoubleTap += BorderDoubleTap;
}
};
Further more the implementation I'm using is to prevent pinch and zoom, something you want to have working. Though this should help you in the right direction.
private void BorderDoubleTap(object sender, GestureEventArgs e)
{
e.Handled = true;
}
private void BorderManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
// suppress zoom
if (Math.Abs(e.DeltaManipulation.Scale.X) > 0.0||
Math.Abs(e.DeltaManipulation.Scale.Y) > 0.0)
e.Handled = true;
}
private void BorderManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
// suppress zoom
if (Math.Abs(e.FinalVelocities.ExpansionVelocity.X) > 0.0 ||
Math.Abs(e.FinalVelocities.ExpansionVelocity.Y) > 0.0)
e.Handled = true;
}
On Mark's direction, I used
private void Border_ManipulationDelta(object sender,
System.Windows.Input.ManipulationDeltaEventArgs e)
{
e.Complete();
_browser.IsHitTestVisible = false;
}
NET C# ,
In my windows phone 7.5 application , I want to make visible the application bar if any item has selected .. So I am making it visible in selected change event. But what is happening in my code is when ever selection change it also triggers LostFocus event and in that event I am making selected index = 0.
Now the resultant of the code is when ever I select any item , application bar gets visible then automatically invisible ( because of lost focus event).
Following is the piece of code .
private void ShopingListItemDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ShopingListItemDetails.SelectedIndex != -1)
{
ApplicationBar.IsVisible = true;
int selind = ShopingListItemDetails.SelectedIndex;
}
}
private void ShopingListItemDetails_LostFocus(object sender, RoutedEventArgs e)
{
ApplicationBar.IsVisible = false;
ShopingListItemDetails.SelectedIndex = -1;
}
I am just at start with .NET C#(XAML) so assuming that selection change event is also triggering LostFocus event.
Please help me what is the real problem behind.Thanks
Zauk
You can use the following hack. Initialize a variable, say selectChanged to False initially in the xaml.cs. In SelectionChanged function change it to True. Now, in the LostFocus function do processing only if the selectChanged variable is false, and if it is true set it back to False
Boolean selectChanged=false;
private void ShopingListItemDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ShopingListItemDetails.SelectedIndex != -1)
{
ApplicationBar.IsVisible = true;
int selind = ShopingListItemDetails.SelectedIndex;
selectChanged=true;
}
}
private void ShopingListItemDetails_LostFocus(object sender, RoutedEventArgs e)
{
if(!selectChanged)
{
ApplicationBar.IsVisible = false;
ShopingListItemDetails.SelectedIndex = -1;
}
selectChanged=false;
}
I think this should solve your problem.
I have n picture boxes. They should perform the following events dynamically:
private void pictureBoxMouseHover(object sender, EventArgs e)
{
if (sender is PictureBox)
{
((PictureBox)sender).BorderStyle = BorderStyle.FixedSingle;
}
}
private void pictureBoxMouseLeave(object sender, EventArgs e)
{
if (sender is PictureBox)
{
((PictureBox)sender).BorderStyle = BorderStyle.None;
}
}
private void MainMaster_Load(object sender, EventArgs e)
{
foreach (var control in Controls)
{
if (sender is PictureBox)
{
PictureBox pb=new PictureBox();
pb.Name = sender.ToString();
pb.MouseHover += new System.EventHandler(this.pictureBoxMouseHover);
pb.MouseLeave += new System.EventHandler(this.pictureBoxMouseHover);
}
}
}
I couldn't find what wrong with this; please help me.
dbaseman is right, you used wrong variable when iterating through controls.
But if you want to add this behavior to all picture boxes, then better solution is to create custom picture box, and simply place it on your form:
public class MyPictureBox : PictureBox
{
protected override void OnMouseHover(EventArgs e)
{
BorderStyle = BorderStyle.FixedSingle;
base.OnMouseHover(e);
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
BorderStyle = BorderStyle.None;
}
}
Create this class, compile app and drag these custom picture boxes from toolbox to your form. They all will display border when mouse hover over picture box.
I think the mistake is here:
foreach (var control in Controls)
{
if (sender is PictureBox)
Sender in this case will be the window. I think you intended control.
foreach (var control in Controls)
{
if (control is PictureBox)
I have had a problem where on some instances in the emulator, when I click the back hardware button the back page loads with the constructor being called and some other time the constructor is not called.Why is this? Is this because its the emulator?
How are you performing navigation? Are you canceling the initial OnNavigatingFrom in order to perform an animation, then listening initiating navigation again after the animation completes?
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
if (_pendingNavigation == null)
{
VisualStateManager.GoToState(this, "LeavingPage", true);
_pendingNavigation = e.Uri;
e.Cancel = true;
}
base.OnNavigatingFrom(e);
}
void LeavingPage_Completed(object sender, EventArgs e)
{
var uri = _pendingNavigation;
NavigationService.Navigate(uri);
_pendingNavigation = null;
}
The bug occurs when you call NavigationService.Navigate(), which then adds a new page instance to the navigation stack. To fix this bug, you need to check and make sure the initial page navigation is a "New" navigation. Something like so:
if (e.NavigationMode == NavigationMode.New && _pendingNavigation == null)
{
VisualStateManager.GoToState(this, "LeavingPage", true);
_pendingNavigation = e.Uri;
e.Cancel = true;
}
Is there a way I can detect this? I want to keep performing an action as long as the user is holding on an icon.
Instead of using the GestureListener for this you could instead use the mouse manipulation events to detect how long to perform your action. For instance:
Listen for MouseLeftButtonDown to know when the user has touched the icon
Keep performing the action until either MouseLeftButtonUp or MouseLeave fire indicating that the user is no longer touching that icon
You may also have to play with MouseEnter for initiating the action
Today only i did the same thing in my project.I'll tell you the basic logic what i implemented(assuming it has to be done on button).Step 1: On the button _ManipulationStarted_ event start a timer with the interval after which you want to fire the repeat action.
Step 2: On the button _ManipulationCompleted_ event stop the timer.
Step 3: If the timer is fired,stop the timer and start another timer with interval = the repeat interval for your action.And inside the second timer fire handler perform your operation only if the control has focus. In this case, where the control is a button, you can check if the button.IsPressed is true then perform action.
The code will look something like:
Button forward=new Button();
DispatcherTimer forwardHoldTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(2) };
forward.ManipulationStarted += (a, b) => { forwardHoldTimer.Start(); };
forward.ManipulationCompleted += (c, d) => { forwardHoldTimer.Stop(); };
forwardHoldTimer.Tick+=(s1,e1)=>
{
forwardHoldTimer.Stop();
DispatcherTimer t = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(100) };
t.Tick += (x, y) =>
{
if (forward.IsPressed)
{
//Your action logic will go here
}
else
t.Stop();
};
t.Start();
};
Hope this helps.
NOTE: Amresh Kumar was correct in suggesting using the manipulation events. Also, I was given the same advice on the Windows Phone App Hubs forums so I've edited this post to reflect the code changes.
Before, the UX was flaky because lifting my finger off the screen didn't always trigger a cancellation. Not surprisingly, the GestureCompleted code in the toolkit appears to be better geared towards touchscreens than are mouse button events.
XAML:
<iconControls:iconUpDownArrow>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Tap="RangeUpTap" Hold="RangeUpHold" GestureCompleted="RangeUpCancel" />
</toolkit:GestureService.GestureListener>
</iconControls:iconUpDownArrow>
code:
private void RangeUpTap(object sender, GestureEventArgs e)
{
RangeIncrementUp(sender, e);
}
private readonly TimeSpan _rangeIncrementTimeSpan = new TimeSpan(1500000);
private readonly DispatcherTimer _rangeIncrementTimer = new DispatcherTimer();
private void RangeUpHold(object sender, GestureEventArgs e)
{
_rangeIncrementTimer.Interval = _rangeIncrementTimeSpan;
_rangeIncrementTimer.Tick += RangeIncrementUp;
_rangeIncrementTimer.Start();
}
private void RangeUpCancel(object sender, GestureEventArgs e)
{
_rangeIncrementTimer.Stop();
_rangeIncrementTimer.Tick -= RangeIncrementUp;
}
private void RangeIncrementUp(object sender, EventArgs e)
{
int range = Convert.ToInt32(tBoxRange.Text);
if (range < 1000)
{
range += 10;
}
tBoxRange.Text = range.ToString();
}