Disable/enable a page on a popup being shown/hidden in wp8 - c#

I am using a windows phone user control to show a popup. I used this because My app may be calling for a log in # several points(not if already logged in). I was able to display the popup(used a class). This is my first time exposure to mobile apps. What I need is to disable the page from which the popup is called and enable it once we are logged in or cancelled the popup. Please find my code below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Controls.Primitives;
namespace Project1.Utilies
{
class TALogin
{
public void display_cspopup()
{
Popup popup = new Popup();
popup.Height = 300;
popup.Width = 400;
popup.VerticalOffset = 200;
Pages.PopupController control = new Pages.PopupController();
popup.Child = control;
popup.IsOpen = true;
control.popuplgnbtn.Click += (s, args) =>
{
popup.IsOpen = false;
};
control.popupcnclbtn.Click += (s, args) =>
{
popup.IsOpen = false;
};
}
}
}
AS you may have guessed, PopupController is the controller created for Popup UI(xaml file).
Thanks,
Akhil

what you can do is have two secondary Grids in your Primary Grid and set the visibility to visible or collapsed as per you require!!
your xaml should look somewhat like this:
<Grid x:name="ParentGrid">
<Grid x:name="ChildGrid1">
<!-- your work -->
</Grid>
<Grid x:name="ChildGrid2">
<!-- your work -->
</Grid>
</Grid>
assume you have a button in your grid, on its click event you can collapse any of the grids in this manner!!
//in click event of the button:
ChildGrid1.Visibility=Visibility.Collapsed;
Hope this helps!! :)

Related

Switching between "Tabs" (via bottom navigation) - flickering, any advice?

I am currently writing a Messenger app for my Guild, currently I got as far as, I can log in and switch between different tabs, that lists currently dummy message titles (like a whisper name).
My goal later is that once you click on one of the messages you can reply / read messages in WhatsApp style (tips welcome here as well).
But my current issue is that I use the "Bottom" navigation menu. I swap the tabs currently with new activies. But whenever I click a button the screen "flickers" like, it's restarting the whole app.
Is there some way to switch "fluid" the upper part of the app, while the menu always stays nicely at the bottom?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Views;
using Android.Widget;
namespace GuildMaster
{
[Activity(Label = "Whisper")]
public class Whisper : Activity, BottomNavigationView.IOnNavigationItemSelectedListener
{
private ListView whisperlist;
private List<string> itemlist;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
BottomNavigationView navigation = FindViewById<BottomNavigationView>(Resource.Id.navigation);
navigation.SetOnNavigationItemSelectedListener(this);
whisperlist = FindViewById<ListView>(Resource.Id.whisper);
itemlist = new List<string>();
itemlist.Add("Tim");
itemlist.Add("Tom");
ArrayAdapter<string> whisper = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist);
whisperlist.Adapter = whisper;
whisperlist.ItemClick += Listnames_ItemClick;
// Create your application here
}
public void Listnames_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
}
public bool OnNavigationItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Resource.Id.navigation_home:
StartActivity(typeof(Whisper));
return true;
case Resource.Id.navigation_dashboard:
StartActivity(typeof(Guild));
return true;
case Resource.Id.navigation_notifications:
StartActivity(typeof(Other));
return true;
}
return false;
}
}
}
you should try working with fragments instead of activities with the bottom navigation, working with an activity means u have to start a completely new screen with a new bottom navigation, if that is what you are doing then it is completely normal to "flicker" when doing so
as a solution, use an activity with an xml that holds a fragment view and a bottom navigation view, and when u switch from the bottom navigation in your activity, switch the fragments loaded within the fragment view.
this can be done with different methods, but i would suggest checking out the Navigation Component from Google, since it will also handle the backstack for you.

Create a custom control in Corel Draw X6 using only VSTA

I am in the process of creating a plugin (or addin) for CorelDraw X6 using VSTA (Visual Studio for Applications) because I like C# and .NET library. I would like to have a button in CorelDraw toolbar, so when a user clicks this button some action happens, for example, a form is showed. For that I use predefined solution VSTAGlobal, that is there for me when I start CorelDraw. Unfortunately, there is NO official documentation (WTF!!!!!) for VSTA in CorelDraw, instead we have VBA (Visual Basic for Applications) documentation and CorelDraw Object Model. I googled a lot and found a few links: some forum post and YouTube video tutorial. The problem is, both guys there create their CustomControl (a buton for example) and simply build it as *.dll and then use VBA script to add the CustomControl to CorelDraw toolbar like this
Sub addLineWidthControl()
Call FrameWork.CommandBars("Standard").Controls. '
AddCustomControl("MyNameSpace.MyCustomControlClass", '
"MyCustomControlAssembly.dll")
End Sub
So, my question is: is there any way to do this using only VSTA?
Additional info:
For example, in the default solution VSTAGlobal there is a Main class with [CgsAddInModule] attribute:
[CgsAddInModule]
public partial class Main
{
private Corel.Interop.VGCore.Application app;
// some other code here...
}
This class has a constructor (note, default and provided by CorelDraw):
[CgsAddInConstructor]
public Main(object _app)
// this constructor probably gets an instance
// of CorelDraw application object.
{
app = _app as Corel.Interop.VGCore.Application;
// will it work if I add some code here?
}
Maybe this is the place where I should add something like this:
app.FrameWork.CommandBars["Standard"]
.Controls.AddCustomControl("MyCustomControlClass");
I did some experiments with this last line of code. I obtained that the Count of Controls is increasing, but still MyCustomControl does not show up in the toolbar.
There is a way to use only C# (I tested this in Corel X8 but it should work in any version that has VSTA). It is a 2 part process though. First you will need to open Macro Manager in Corel and edit the VSTAGlobal solution. For example, if you want to add a button and a slider, add this method:
[CgsAddInMacro]
public void Add()
{
string controlAssembly = #"C:\VSTS\ScratchProjects\CoreDrawPoC\CoreDrawPoC\bin\Debug\CoreDrawPoC.dll";
var mySlider = app.FrameWork.CommandBars["Standard"].Controls.AddCustomControl("CoreDrawPoC.MySlider", controlAssembly);
mySlider.Caption = "Border Sizing Slider Caption";
mySlider.ToolTipText = "Border Sizing Slider Tooltip";
var myButton = app.FrameWork.CommandBars["Standard"].Controls.AddCustomControl("CoreDrawPoC.ButtonSample", controlAssembly);
myButton.Caption = "Rectanlge Selector";
mySlider.ToolTipText = "Rectanlge Selector Tooltip";
}
Once you add this code, you will need to add a .dll for a solution to the folder listed above. Open Visual Studio 2015 and create a new project (mine was named CoreDrawPoC). It needs to be a WPF User Control Library project. Create 2 .xaml files with. First will be the slider:
<UserControl x:Class="CoreDrawPoC.MySlider"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CoreDrawPoC"
mc:Ignorable="d" >
<Slider x:Name="mySlider" Width="100" Minimum=".5" Maximum="10" TickFrequency=".5" IsSnapToTickEnabled="True" ValueChanged="mySlider_ValueChanged"/>
</UserControl>
Code behind is:
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CoreDrawPoC
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class MySlider : UserControl
{
Corel.Interop.VGCore.Application appDraw = null;
public MySlider()
{
InitializeComponent();
}
public MySlider(object app)
{
InitializeComponent();
appDraw = (Corel.Interop.VGCore.Application)app;
}
private void mySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (appDraw != null && appDraw.ActiveDocument != null && appDraw.ActiveShape != null)
{
double width = appDraw.ConvertUnits((double)e.NewValue, Corel.Interop.VGCore.cdrUnit.cdrPoint, Corel.Interop.VGCore.cdrUnit.cdrInch);
appDraw.ActiveSelectionRange.SetOutlineProperties(width);
}
}
}
}
Then create the button:
<UserControl x:Class="CoreDrawPoC.ButtonSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CoreDrawPoC"
mc:Ignorable="d">
<Button x:Name="buttonSample" Click="buttonSample_Click" Width="24" Height="24" >
<Button.Template>
<ControlTemplate>
<Image Source="C:\CorelIcons\Two.bmp"/>
</ControlTemplate>
</Button.Template>
</Button>
</UserControl>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CoreDrawPoC
{
/// <summary>
/// Interaction logic for ButtonSample.xaml
/// </summary>
public partial class ButtonSample : UserControl
{
Corel.Interop.VGCore.Application appDraw = null;
public ButtonSample()
{
InitializeComponent();
}
public ButtonSample(object app)
{
InitializeComponent();
appDraw = (Corel.Interop.VGCore.Application)app;
}
private void buttonSample_Click(object sender, RoutedEventArgs e)
{
SelectOfType("rectangle");
}
private void SelectOfType(string strType)
{
string strQuery = null;
Corel.Interop.VGCore.ShapeRange srGroup = default(Corel.Interop.VGCore.ShapeRange);
Corel.Interop.VGCore.ShapeRange srTopOnly = default(Corel.Interop.VGCore.ShapeRange);
strQuery = "#type='" + strType + "'";
srGroup = appDraw.ActivePage.Shapes.FindShapes("", 0, true, strQuery);
srTopOnly = appDraw.ActivePage.Shapes.FindShapes("", 0, false, strQuery);
srTopOnly.CreateSelection();
appDraw.ActivePage.Shapes.FindShapes("", 0, false, strQuery).CreateSelection();
//if (srTopOnly.Count == srGroup.Count)
//{
// lblWarning.Visibility = System.Windows.Visibility.Hidden;
//}
//else
//{
// lblWarning.Visibility = System.Windows.Visibility.Visible;
//}
}
}
}
Once that is done, you will want to compile the code. Also, you will want to create the image C:\CorelIcons\Two.bmp. It is just a 24x24 bitmap that looks however you want it to look. Then compile the project. You will need to this will CorelDraw closed.
Once it compiles successfully, you will want to go and run your VSTA macro to add the button and slider. This macro will only need to be run 1 time! After than, it will connect directly to the code in your dll. If you change anything in the dll and update it while Corel is closed, it changes it. This includes the images.
Finally, I learned how to do this from 2 blog posts and I only changed it to add a button to the Standard command bar and to use purely C#. Those posts are:
https://forum.oberonplace.com/blog.php?b=165
https://forum.oberonplace.com/blog.php?b=166

Is this a bug in DotNet 4 WPF Spell Checking?

I have:
Created a Windows forms project.
Created a UserControl to hold a WPF TextBox.
Added a CustomDictionary to the TextBox's SpellCheck.
Added the UserControl to my Windows Form.
XAML is used to add the WPF textbox to the user control:
<UserControl x:Class="TestElementHost.SpellBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="248" d:DesignWidth="250">
<Grid>
<TextBox Name="txtWPF" />
</Grid>
</UserControl>
Here is the form code (buttons added in the VS designer file):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestElementHost
{
public partial class Form1 : Form
{
private System.Windows.Forms.Integration.ElementHost elementHost1;
private SpellBox spellBox1;
public Form1()
{
InitializeComponent();
this.elementHost1 = new System.Windows.Forms.Integration.ElementHost();
this.spellBox1 = new TestElementHost.SpellBox();
this.elementHost1.Location = new System.Drawing.Point(27, 12);
this.elementHost1.Name = "elementHost1";
this.elementHost1.Size = new System.Drawing.Size(269, 296);
this.elementHost1.TabIndex = 0;
this.elementHost1.Text = "elementHost1";
this.elementHost1.Child = this.spellBox1;
this.Controls.Add(this.elementHost1);
}
private void Form1_Load(object sender, EventArgs e)
{
spellBox1.txtWPF.SpellCheck.IsEnabled = true;
spellBox1.txtWPF.SpellCheck.CustomDictionaries.Add(new Uri(Application.StartupPath + #"\MyDictionary.lex"));
}
private void button1_Click(object sender, EventArgs e)
{
spellBox1.txtWPF.Text = "my bbad word."; // bbad is in the CustomDictionary
}
private void button2_Click(object sender, EventArgs e)
{
spellBox1.txtWPF.IsEnabled = false;
spellBox1.txtWPF.IsEnabled = true;
// spellBox1.txtWPF.SpellCheck.IsEnabled = false;
// spellBox1.txtWPF.SpellCheck.IsEnabled = true;
}
}
}
This works quite happily and words in the CustomDictionary are ignored, until I try changing the IsEnabled, IsReadOnly or the Visibility property. For example, set IsReadOnly to true then straight back to false again and suddenly words that are in the customdictionary are redlined.
The way I am getting round this is to set SpellCheck.IsEnabled to false then back to true on consecutive lines when I need to allow users to edit text in the control. This seems to bring the customdictionary back into play.
Has anyone else had this problem? Is this a bug or have I missed something?
It looks like a "feature" (thanks for verifying this Joachim):
If you are using the custom dictionary, then change the visbility, enabled or read only attributes of the WPF textbox or the user control, the spell checker ignores the custom dictionary.
To get round this, disable then re-enable spell checking.
This applies to dot net runtime v4.0.30319

Adding controls to the Panel works the first couple of times, then fritzes out

Here's screenshots:
Here's the code I'm using to load the pictureBoxes to the Panel:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WebServiceScanner
{
public partial class MainForm : Form
{
int pictureYPosition = 8;
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LoadImageFromScanner();
}
private void LoadImageFromScanner()
{
Image pic = Image.FromFile(#"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg");
PictureBox pictureHolder = new PictureBox();
pictureHolder.Image = pic;
pictureHolder.SizeMode = PictureBoxSizeMode.StretchImage;
pictureHolder.Size = new System.Drawing.Size(180, 250);
pictureHolder.Location = new Point(13, pictureYPosition);
panel1.Controls.Add(pictureHolder);
pictureYPosition += 258;
}
}
}
What could be causing the problem? The Panel has Autoscroll set to true, so maybe that's causing the issue?
IMPORTANT EDIT:
The pictures load absolutely FINE, if I don't touch the scrollbar and leave it in it's initial position (topmost). If I scroll down and add pictures it seems it has a different idea of where the point I'm giving it really is.
Any suggestions?
A panel scrolls its content by adjusting the Location property of its child controls when you move the scrollbar. You need to do this yourself when you add a picture. Fix:
pictureHolder.Location = new Point(13, pictureYPosition + panel1.AutoScrollPosition.Y);
Not sure if this will help. Before you add it to panel call panel1.SuppressLayout() then afterwards call panel1.ResumeLayout(true).
Another option is use a FlowLayoutPanel instead of manually incrementing the distance every time.
The solution that worked for me was to supresslayout and resumelayout, the one of Scott.
To substract the autoscroll Y position, didnt worked at all.

How can I make a hover info bubble appear on mouseover in WPF?

I want to make bubble of text appear when the mouse is over a TextBlock.
The following code is the closest I can get but it just injects text into TextBox.Text itself and changes the color. I want to have a e.g. Border/StackPanel/TextBlock above the original textblock floating on a different layer during mouseover.
How can I make a hover panel similar to a web experience with the acronym tag?
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace TestHover29282
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
TextBlock tb = new TextBlock();
tb.Text = "test";
tb.MouseEnter += new MouseEventHandler(tb_MouseEnter);
tb.MouseLeave += new MouseEventHandler(tb_MouseLeave);
MainStackPanel.Children.Add(tb);
}
void tb_MouseLeave(object sender, MouseEventArgs e)
{
TextBlock tb = sender as TextBlock;
tb.Background = new SolidColorBrush(Colors.Transparent);
tb.Text = "test";
}
void tb_MouseEnter(object sender, MouseEventArgs e)
{
TextBlock tb = sender as TextBlock;
tb.Background = new SolidColorBrush(Colors.Orange);
tb.Text += " - this should be in a popup bubble.";
}
}
}
couple of ways you could do it, one use a tool tip with a custom style.
alternativly, you can use a popup control, a third option would be to use an adorner.
My gut says you want a tooltip, tho.
<TextBlock ToolTip="stuff, could even be a custom control, etc" Text="my text" />
you can then use the ToolTipService attachable properties to set a variety of options for said tooltip, from delays to tooltip positions
Tooltip property

Categories