Textblock opening viewbox and not navigating - c#

i am having a problem with my textblock navigating to a new page! , well the navigation is not the problem!, i have a viewbox that has storyboards connected with it, so when i click on it, the viewbox expands or collapse, but next to this viewbox i have a textblock that has a colour on it, when i click on that coloured textbox, it should navigate to another screen , but what it does is, it first expands the viewbox then in navigates!, any ideas?
after clicked it opens up , and then navigates,want this to not expand when clicked on the green block
this is coding for viewbox and the textblock_tap event:
private void viewboxHeader_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
vb = (Viewbox)sender;
Storyboard sbExpand = new Storyboard();
Storyboard sbCollapse = new Storyboard();
sbExpand = (Storyboard)vb.TryFindResource("Expand");
sbCollapse = (Storyboard)vb.TryFindResource("Collapse");
string Status = vb.Tag.ToString();
if (Status == "1")
{
descend = false;
sbCollapse.Begin();
vb.Tag = 0;
}
if (Status == "0")
{
descend = true;
sbExpand.Begin();
vb.Tag = 1;
}
}
private void TextBlock_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
this.NavigationService.Navigate(new Uri("/UI/frmWFDocumentDetail.xaml", UriKind.Relative));
}
Thanks in advance!
i use Visual Studio 2012/silverlight/windows phone 8 app! windows 8 sdk

Just mark the event as handled to prevent it from propagating to the parent control:
private void TextBlock_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
e.Handled = true;
this.NavigationService.Navigate(new Uri("/UI/frmWFDocumentDetail.xaml", UriKind.Relative));
}

Related

How to make button a invisible when other buttons are clicked

I'm creating a new project with Guna Framework UI
I set another button(btnMove) behind the first button "Dashboard" that moves to the new button location that gets clicked in that left panel.
I want to make the btnMove to be invisible when I click buttons from the right panel.
These are my codes
//moving disabled button across buttons in the same panel when clicked
private void MoveButton(object sender)
{
Guna2Button b = (Guna2Button)sender;
btnMove.Visible = true;
btnMove.FillColor = Color.White;
btnMove.Animated = true;
btnMove.Location = new Point(b.Location.X + 24, b.Location.Y + 1);
btnMove.SendToBack();
}
//end here
private void guna2Button1_CheckedChanged(object sender, EventArgs e)
{
//Calling the move function
MoveButton(sender);
}
I tried to set the btnMove to be invisible only when I click on the buttons on the right panel but it doesn't seem to work
private void guna2Button3_Leave(object sender, EventArgs e)
{
guna2Button1.Checked = false;
btnMove.Visible = false;
}

UWP - save item

in XAML i created button and when i click on the button then background will be changed to red color(because i set it) but if i close my application and then again start application so background is not red. What i need to do is keep background there like before(when i clicked on button) so have red background if i again start application. Your help will be for me very important. Thank you experts. Btw this is code for button now: :).
private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
{
background.Background = new SolidColorBrush(Colors.Red);
}
you need to save the selected color; or save somwething some you can determine what color it has to be. In the constructor or your page read this value and set the right color.
you can use localsettings to save this.
ApplicationData.Current.LocalSettings.Values["BGColor"] = "Red";
for example.
In the constructor:
if ( ApplicationData.Current.LocalSettings.Values["BGColor"] == "Red")
{
background.Background = new SolidColorBrush(Colors.Red);
}
full sample:
public MainPage()
{
this.InitializeComponent();
if ((string)ApplicationData.Current.LocalSettings.Values["BGColor"] == "Red")
LayoutRoot.Background = new SolidColorBrush(Colors.Red);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ApplicationData.Current.LocalSettings.Values["BGColor"] = "Red";
LayoutRoot.Background = new SolidColorBrush(Colors.Red);
}

WPF trouble getting TextBox focused

On mouse event I'm trying to create TextBox, add it to Grid, select all and focus keyboard. But can't get it working:
private void timeCodeEdit(object sender, MouseEventArgs e)
{
Grid grid = (Grid) ((Label) sender).Parent;
TextBox text = new TextBox();
text.Margin = new Thickness(0, 0, 75, 0);
text.Text = "aaaa";
grid.Children.Add(text);
text.LostFocus += lostFocus;
Keyboard.Focus(text);
text.SelectAll();
}
I've tried Keyboard.Focus(text); and text.Focus();. And if I do this:
private void lostFocus(object sender, RoutedEventArgs e)
{
Keyboard.Focus(sender as TextBox);
e.Handled = true;
}
I'm getting StackOverflowException, cause it lost focus right after focus.
Maybe someone can help me about this?
I'll post answer:
text.LostKeyboardFocus += Text_LostKeyboardFocus;
and:
private void Text_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
var name = ((FrameworkElement)e.NewFocus).Name;
Console.Write(name);
}
Helped me find out that my ScrollViewer is getting focus, so Focusable="False" for ScrollViewer solved the problem.

Setting location of runtime controls

I have added a listBox containing a list and a toolStrip in my application. These are used to select control to added runtime in a panel. (I have added an image. The toolStrip and listBox are on the left and right side respectively.) Now what I do with these controls is,
1 - I select an item from toolStrip or listBox
2 - A runtime control is made and shown on the form
3 - On Mouse_Up event, the control is set on the Panel (If it is in the panel.)
Now the question is, as shown in the image, the runtime control is not at the tip of the cursor. I want these runtime controls on the tip of the cursor.
Below is the Image.
EDIT: Below is the code.:
private void listBox_MouseDown(object sender, MouseEventArgs e)
{
this.globalLabel1 = new Label();
this.globalLabel1.Text = this.listBox.SelectedItem.ToString() + " : ";
//other label properties like, tag, name, events, font etc.
}
private void listBox_MouseMove(object sender, MouseEventArgs e)
{
if (this.globalLabel1 != null)
{
this.globalLabel1.Left = System.Windows.Forms.Cursor.Position.X
- this.Location.X;
this.globalLabel1.Top = System.Windows.Forms.Cursor.Position.Y
- this.Location.Y;
this.globalLabel1.Show();
this.lPanel.SendToBack();
}
}
private void listBox_MouseUp(object sender, MouseEventArgs e)
{
this.globalLabel1.Parent = this.lPanel;
this.globalLabel1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
this.globalLabel1.Left = Cursor.Position.X
- /*Cursor.Size.Height -*/ this.lPanel.Location.X
- this.Location.X;
this.globalLabel1.Top = Cursor.Position.Y
- /*Cursor.Size.Width -*/ this.lPanel.Location.Y
- this.Location.Y;
}
Thanks.
You have to set the Location of your runtime added control relatively to the parent, you can use the method PointToClient like this:
private void listBox_MouseUp(object sender, MouseEventArgs e) {
globalLabel1.Parent = lPanel;
globalLabel1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
globalLabel1.Location = lPanel.PointToClient(Cursor.Position);
}
i). I don't know why are you not using Panel_MoveUP event, Because you wan to place it on panel.
ii). At Panel_moveUp you have to make little bit position change to cursor position by Hit and trail method, I not sure about this why is this difference coming so.
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
this.globalLabel1 = new Label();
this.globalLabel1.Text = this.listBox1.SelectedItem.ToString() + " : ";
//other label properties like, tag, name, events, font etc.
}
//////////////////////////USE PANEL_MOVEUP EVENT//////////////
private void lPanel_MouseMove(object sender, MouseEventArgs e)
{
if (this.globalLabel1 != null)
{
this.globalLabel1.Left = System.Windows.Forms.Cursor.Position.X-50 // Change
- this.Location.X;
this.globalLabel1.Top = System.Windows.Forms.Cursor.Position.Y-100 //Change
- this.Location.Y;
this.globalLabel1.Show();
this.lPanel.SendToBack();
this.lPanel.Controls.Add(globalLabel1);
}
}

WPF C# Image MouseDown to switch pages

I have 3 Images with Mouse Down event like this :
private void button12_MouseDown(object sender, MouseButtonEventArgs e) // Back to choose story menu page.
{
//if button 2 is pressed then show FoodKing
// if button 1 is pressed then show Grasshopper
stackPanelHome.Visibility = System.Windows.Visibility.Hidden;
pageTransition1.Visibility = System.Windows.Visibility.Visible;
pageTransition1.ShowPage(What to put in here?);
}
private void button2_MouseDown(object sender, MouseButtonEventArgs e) // Food fit for a king.
{
FoodKing controlpage = new FoodKing(); // Calling user control page
stackPanelHome.Visibility = System.Windows.Visibility.Hidden;
pageTransition1.Visibility = System.Windows.Visibility.Visible;
pageTransition1.ShowPage(controlpage);
}
private void button1_MouseDown(object sender, MouseButtonEventArgs e) // Grasshopper
{
GrasshopperMenu controlpage = new GrasshopperMenu(); / Calling user control page
stackPanelHome.Visibility = System.Windows.Visibility.Hidden;
pageTransition1.Visibility = System.Windows.Visibility.Visible;
pageTransition1.ShowPage(controlpage);
}
In the first page , there is 2 icon , 1 is FoodKing , 1 is Grasshopper then they choose which image to press on and each icon have many buttons and leads to else where , so i create a menu page to revert the user back to the page that they have selected in the beginning ( FoodKing or GrassHopper) . But how do i do this? See my code above.
Page currentPage;
private void button12_MouseDown(object sender, MouseButtonEventArgs e) // Back to choose story menu page.
{
stackPanelHome.Visibility = System.Windows.Visibility.Hidden;
pageTransition1.Visibility = System.Windows.Visibility.Visible;
if(currentPage != null)
{
pageTransition1.ShowPage(currentPage);
}
}
private void button2_MouseDown(object sender, MouseButtonEventArgs e) // Food fit for a king.
{
FoodKing controlpage = new FoodKing(); // Calling user control page
stackPanelHome.Visibility = System.Windows.Visibility.Hidden;
pageTransition1.Visibility = System.Windows.Visibility.Visible;
pageTransition1.ShowPage(controlpage);
currentPage = controlpage;
}
private void button1_MouseDown(object sender, MouseButtonEventArgs e) // Grasshopper
{
GrasshopperMenu controlpage = new GrasshopperMenu(); // Calling user control page
stackPanelHome.Visibility = System.Windows.Visibility.Hidden;
pageTransition1.Visibility = System.Windows.Visibility.Visible;
pageTransition1.ShowPage(controlpage);
currentPage = controlpage;
}

Categories

Resources