How to prevent vertical scroll bar to lap my stack panels wpf - c#

I am wondering how could I prevent vertical scroll bar from lapping my stack panels.
I am working on small wpf app where customers can add articles(drinks) to a something like cart, and when user click on article its added to the right part of window in stack panel, this is how it looks a like:
But I have problem when I add more than lets say 5-6 items to my stack panel, than vertical scroll bar is appearing and this is what's happening (notice vertical scroll bar to the right) its laping "x1":
How could I prevent this guy? Is it possible to move content to the left or something like that without laping my items/articles ...
If the code of how I add items to stackPanel is needed, I will post it in a sec?
HERE IS MY FULL CODE ABOUT THIS PART:
public MyDrinksPanel(int id, int groupID, double price,double priceHappy, string text, int fontSize, int numberSize, int buttonWidth, int buttonHeight, int margin, Thickness border, byte[] image)
: base()
{
this.Width = buttonWidth+90;
this.Height = buttonHeight;
image.Source = GetimageFromByte(image);
ID = id;
groupID = groupID;
price = price;
priceHappy = priceHappy;
DugmePanel.HorizontalAlignment = HorizontalAlignment.Center;
DugmePanel.VerticalAlignment = VerticalAlignment.Center;
DugmePanel.Orientation = Orientation.Horizontal;
DugmePanel.MaxWidth = DugmePanel.Width = buttonWidth;
//DugmePanel.Height = 70;
DugmePanel.Height = DugmePanel.MaxHeight = this.Height;
BrushConverter MyBrush = new BrushConverter();
DugmePanel.Background = (Brush)MyBrush.ConvertFrom("#50000000");
_image.Width = 120;
_image.Height = buttonHeight;
_image.HorizontalAlignment = HorizontalAlignment.Left;
_image.VerticalAlignment = VerticalAlignment.Center;
BrushConverter MyBrush2 = new BrushConverter();
RightNumberPanel.HorizontalAlignment = HorizontalAlignment.Right;
RightNumberPanel.VerticalAlignment = VerticalAlignment.Center;
RightNumberPanel.Orientation = Orientation.Horizontal;
RightNumberPanel.Width = RightNumberPanel.MaxWidth = this.Width - DugmePanel.Width;
RightNumberPanel.Height = RightNumberPanel.MaxHeight = this.Height;
NumberLabel.FontFamily = Util.Font; //new System.Windows.Media.FontFamily("HelveticaNeueLTStd-Bd.otf#Helvetica Neue LT Std");
ArticleNameLabel.VerticalContentAlignment = VerticalAlignment.Center;
ArticleNameLabel.HorizontalContentAlignment = HorizontalAlignment.Left;
ArticleNameLabel.FontSize = fontSize;
ArticleNameLabel.Foreground = System.Windows.Media.Brushes.White;
ArticleNameLabel.MaxWidth = _image.Width+45; //- 3;
ArticleNameLabel.FontFamily = Util.Font;//new System.Windows.Media.FontFamily("HelveticaNeueLTStd-Bd.otf#Helvetica Neue LT Std");
NumberLabel.Height = NumberLabel.MaxHeight = this.Height;
NumberLabel.FontSize = numberSize;
NumberLabel.Margin = new Thickness(0, 0, 0, 0);
NumberLabel.VerticalAlignment = VerticalAlignment.Center;
NumberLabel.HorizontalAlignment = HorizontalAlignment.Right;
NumberLabel.HorizontalContentAlignment = HorizontalAlignment.Right;
NumberLabel.Foreground= System.Windows.Media.Brushes.White;
NumberLabel.FontWeight = FontWeights.Bold;
BrushConverter MyBrush3 = new BrushConverter();
NumberLabel.Background = (Brush)MyBrush3.ConvertFrom("#83D744");
NumberLabel.Foreground = new SolidColorBrush(Colors.Black);
ArticleNameLabel.Content = text;
NumberLabel.Content = "x1";
DugmePanel.Children.Add(image);
DugmePanel.Children.Add(ArticleNameLabel);
RightNumberPanel.Children.Add(NumberLabel);
Rectangle rct = new Rectangle();
rct.Fill = System.Windows.Media.Brushes.White;
rct.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
rct.Height = 2;
//rct.Width = 100;
_animations = new DoubleAnimation(numberSize, numberSize + 15, new Duration(new TimeSpan(0, 0, 0, 0, 300)));
_animations.AutoReverse = true;
this.Margin = border;
this.Orientation = Orientation.Horizontal;
StackPanel spNew = new StackPanel();
spNew.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
spNew.Orientation = System.Windows.Controls.Orientation.Horizontal;
spNew.Children.Add(DugmePanel);
spNew.Children.Add(RightNumberPanel);
StackPanel spNew2 = new StackPanel();
spNew2.Orientation = System.Windows.Controls.Orientation.Vertical;
spNew2.Children.Add(spNew);
this.Children.Add(spNew2);
}
I dont have a lot about XAML HERE:
This is only part:
<ScrollViewer x:Name="ScrollerOnTheRight" Margin="0,0,0,60" HorizontalScrollBarVisibility="Disabled" Grid.Row="1" Grid.Column="2" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Grid.Row="1" x:Name="stackRacun" Grid.Column="2"/>
</ScrollViewer>
Thanks guys,
Cheers

Related

Border wont apply programatically to my grid WPF C#

I have problems with Styling my grid, I am working on small app for caffe bars lets say, customer is able to choose drink from the middle of screen and drink will be shown in the right part of screen in my grid, this is how that looks like right now (when customer choose something - lets say Coke, sprite etc.):
This is my code for now :
public DrinksPanel(byte[] image)
: base()
{
BrushConverter MyBrush8 = new BrushConverter();
var myBorder = new Border();
myBorder.Background = (Brush)MyBrush8.ConvertFrom("#83D744");
Thickness marginT = this.Margin;
marginT.Top = 10;
this.Margin = marginT;
ColumnDefinition col1 = new ColumnDefinition();
col1.Width = new GridLength(45);
ColumnDefinition col2 = new ColumnDefinition();
col2.Width = new GridLength(80, GridUnitType.Star);
ColumnDefinition col3 = new ColumnDefinition();
col3.Width = new GridLength(45);
this.ColumnDefinitions.Add(col1);
this.ColumnDefinitions.Add(col2);
this.ColumnDefinitions.Add(col3);
this.Height = 45;
this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
this.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
ArticleNameLabel.VerticalContentAlignment = VerticalAlignment.Center;
ArticleNameLabel.HorizontalContentAlignment = HorizontalAlignment.Left;
ArticleNameLabel.FontSize = fontSize;
ArticleNameLabel.Foreground = System.Windows.Media.Brushes.White;
ArticleNameLabel.FontFamily = Util.Font;//new System.Windows.Media.FontFamily("HelveticaNeueLTStd-Bd.otf#Helvetica Neue LT Std");
ArticleNameLabel.Content = tekst;
ArticleNameLabel.SetValue(Grid.RowProperty, 0);
ArticleNameLabel.SetValue(Grid.RowSpanProperty, 1);
ArticleNameLabel.SetValue(Grid.ColumnProperty, 1);
ArticleNameLabel.SetValue(Grid.ColumnSpanProperty, 1);
ArticleNameLabel.Width = Double.NaN;
ArticleNameLabel.Height = Double.NaN;
QuantityNumberLabel.Width = Double.NaN;
QuantityNumberLabel.Height = Double.NaN;
QuantityNumberLabel.SetValue(Grid.RowProperty, 0);
QuantityNumberLabel.SetValue(Grid.RowSpanProperty, 1);
QuantityNumberLabel.SetValue(Grid.ColumnProperty, 2);
ArticleNameLabel.SetValue(Grid.ColumnSpanProperty, 1);
QuantityNumberLabel.HorizontalAlignment = HorizontalAlignment.Center;
QuantityNumberLabel.VerticalAlignment = VerticalAlignment.Center;
QuantityNumberLabel.FontFamily = Util.Font;
QuantityNumberLabel.FontSize = numberSize;
QuantityNumberLabel.Content = "x1";
QuantityNumberLabel.Foreground = System.Windows.Media.Brushes.White;
BrushConverter MyBrush3 = new BrushConverter();
QuantityNumberLabel.Background = (Brush)MyBrush3.ConvertFrom("#83D744");
_image.Width = Double.NaN;
_image.Height = Double.NaN;
_image.HorizontalAlignment = HorizontalAlignment.Stretch;
_image.VerticalAlignment = VerticalAlignment.Stretch;
_image.SetValue(Grid.RowProperty, 0);
_image.SetValue(Grid.RowSpanProperty, 1);
_image.SetValue(Grid.ColumnProperty, 0);
_image.SetValue(Grid.ColumnSpanProperty, 1);
Image.Source = GetSlikaFromByte(image);
Rectangle background = new Rectangle();
background.SetValue(Grid.RowProperty, 0);
background.SetValue(Grid.RowSpanProperty, 1);
background.SetValue(Grid.ColumnProperty, 0);
background.SetValue(Grid.ColumnSpanProperty,3);
background.HorizontalAlignment = HorizontalAlignment.Stretch;
background.VerticalAlignment = VerticalAlignment.Stretch;
background.Width = Double.NaN;
background.Height = Double.NaN;
background.Fill = (Brush)MyBrush.ConvertFrom("#50000000");
_animation = new DoubleAnimation(numberSize, numberSize + 15, new Duration(new TimeSpan(0, 0, 0, 0, 300)));
_animation.AutoReverse = true;
this.Children.Add(background);
this.Children.Add(_image);
this.Children.Add(ArticleNameLabel);
this.Children.Add(QuantityNumberLabel);
}
***So my question is guys, how could apply
myborder
around grid?***
If anyone could help me about this I would appreciate that so much =)

Popup Not Showing

On a tap event I would like to show a popup all within code behind, but my popup is not displaying?
void PopupDisplay_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
if (sender != null)
{
p = new Popup
{
Width = 480,
Height = 580,
HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
VerticalAlignment = System.Windows.VerticalAlignment.Center
};
Border b = new Border();
b.BorderBrush = new SolidColorBrush(Colors.Gray);
b.BorderThickness = new Thickness(2);
b.Margin = new Thickness(10, 10, 10, 10);
p.Child = b;
p.IsOpen = true;
}
}
Think you're trying to Popup over a top-level control like a Pivot which is very buggy.
See Popup with Pivots
If it was a Grid, it would pop up without problem. To fix this you will have to add it to the same visual level as the Pivot like so:
<Grid x:Name="ContentPanel" Margin="0,0,0,0">
<phone:Pivot x:Name="MainDisplay">
<!-- more code -->
</phone:Pivot>
</Grid>
Then in your code-behind
// I made with a thickness of 100, so we can see the border better
Popup p;
p = new Popup
{
Width = 480,
Height = 580,
VerticalOffset = 0
};
Border b = new Border();
b.BorderBrush = new SolidColorBrush(Colors.Red);
b.BorderThickness = new Thickness(100);
b.Margin = new Thickness(10, 10, 10, 10);
b.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
b.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
p.Child = b;
// add it to the same level as the pivot to over ride pivot
this.ContentPanel.Children.Add(p);
p.IsOpen = true;

c# Why stackpanel don't resize?

I am using silverlight and have to code in c# not xaml and i have a grid (myGrid) with 1 row and 1 column. This Grid further contain Border(rect) and this rect contains another grid (childGrid)inside having 1 row and 3 columns.
And this smallGrid further contains a stackpanel (sp) in second column whose size formed dynamically but smallGrid dont resize according to the growing size of stackpanel sp.
My code is like this:
Grid myGrid = new Grid();
myGrid.Width = 750;
myGrid.HorizontalAlignment = HorizontalAlignment.Left;
myGrid.VerticalAlignment = VerticalAlignment.Top;
myGrid.ShowGridLines = false;
ColumnDefinition colDef1 = new ColumnDefinition();
myGrid.ColumnDefinitions.Add(colDef1);
RowDefinition rowDef1 = new RowDefinition();
myGrid.RowDefinitions.Add(rowDef1);
Border rect = new Border();
rect.Width = g.Width;
rect.Height = g.Height;
rect.BorderThickness = new Thickness(2);
rect.BorderBrush = new SolidColorBrush(Colors.LightGray);
Grid childGrid = new Grid();
ColumnDefinition colDef1 = new ColumnDefinition();
ColumnDefinition colDef2 = new ColumnDefinition();
ColumnDefinition colDef3 = new ColumnDefinition();
childGrid.ColumnDefinitions.Add(colDef1);
childGrid.ColumnDefinitions.Add(colDef2);
childGrid.ColumnDefinitions.Add(colDef3);
int NumberOfRadioButton = 0;
StackPanel sp = new StackPanel();
foreach(var item in param.Component.Attributes.Items) {
NumberOfRadioButton++;
RadioButton rb = new RadioButton();
rb.GroupName = item;
rb.Content = item;
sp.Children.Add(rb);
}
Grid.SetRow(sp, 1);
Grid.SetColumn(sp, 1);
childGrid.Height = sp.Height;
childGrid.Children.Add(sp);
TextBlock txtblk1ShowStatus = new TextBlock();
TextBlock txtblkLabel = new TextBlock();
txtblkLabel.Text = param.Label;
Grid.SetColumn(txtblkLabel, 0);
Grid.SetRow(txtblkLabel, 1);
childGrid.Children.Add(txtblkLabel);
txtblk1ShowStatus.Text = param.Name;
Grid.SetColumn(txtblk1ShowStatus, 2);
Grid.SetRow(txtblk1ShowStatus, 1);
childGrid.Children.Add(txtblk1ShowStatus);
rect.Child = childGrid;
Grid.SetRow(rect, 1);
myGrid.Children.Add(rect);
The size of myGrid and childGrid must grow dynamically according to the increasing stackpanel size on dynamically created radio buttons? Because all the radio buttons are not displayed in column 2 please see the last radiobutton in snapshot belowis not displayed because of border crossing ("Very High", just after "High"):
EDIT: I even tried these 3 steps but it still the same:
(1)Remove rect.Width = g.Width; rect.Height = g.Height; childGrid.Height = sp.Height;
(2)add rowdef.Height= new GridLength(1, GridUnitType.Auto);(because i am expanding vertically)
(3) add sp.Orientation = Orientation.Vertical;
Edit2 : myGrid is liek this:
Grid myGrid = new Grid();
myGrid.Width = 750;
myGrid.HorizontalAlignment = HorizontalAlignment.Left;
myGrid.VerticalAlignment = VerticalAlignment.Top;
myGrid.ShowGridLines = false;
ColumnDefinition colDef1 = new ColumnDefinition();
myGrid.ColumnDefinitions.Add(colDef1);
int totalRows = p.Parameter.Count() + p.Separator.Count();
for (int i = 0; i < totalRows; i++)
{
myGrid.RowDefinitions.Add(new RowDefinition());
}
EDIT3: (my changed code after bit's suggestion)
Border rect = new Border();
// rect.Width = g.Width;
// rect.Height = g.Height;
rect.BorderThickness = new Thickness(2);
rect.BorderBrush = new SolidColorBrush(Colors.LightGray);
Grid childGrid = new Grid();
ColumnDefinition colDef1 = new ColumnDefinition();
ColumnDefinition colDef2 = new ColumnDefinition();
ColumnDefinition colDef3 = new ColumnDefinition();
RowDefinition rowdef = new RowDefinition();
childGrid.ColumnDefinitions.Add(colDef1);
childGrid.ColumnDefinitions.Add(colDef2);
childGrid.ColumnDefinitions.Add(colDef3);
childGrid.RowDefinitions.Add(rowdef);
rowdef.Height= new GridLength(1, GridUnitType.Auto);
int NumberOfRadioButton =0;
StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Vertical;
foreach (var item in param.Component.Attributes.Items)
{
NumberOfRadioButton++;
RadioButton rb = new RadioButton();
rb.GroupName = item;
rb.Content = item;
sp.Children.Add(rb);
}
Grid.SetRow(sp, LoopCount);
Grid.SetColumn(sp, 1);
childGrid.ShowGridLines = true;
// rect.Height = double.NaN;
childGrid.Children.Add(sp);
TextBlock txtblk1ShowStatus = new TextBlock();
TextBlock txtblkLabel = new TextBlock();
txtblkLabel.VerticalAlignment = System.Windows.VerticalAlignment.Center;
txtblkLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
txtblkLabel.TextAlignment = System.Windows.TextAlignment.Center;
txtblkLabel.FontWeight = FontWeights.Bold;
txtblkLabel.FontSize = 15;
txtblkLabel.FontStyle = FontStyles.Normal;
txtblkLabel.Padding = new Thickness(5, 10, 5, 10);
txtblkLabel.Text = param.Label;
Grid.SetColumn(txtblkLabel, 0);
Grid.SetRow(txtblkLabel, LoopCount);
childGrid.Children.Add(txtblkLabel);
txtblk1ShowStatus.VerticalAlignment = System.Windows.VerticalAlignment.Center;
txtblk1ShowStatus.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
txtblk1ShowStatus.TextAlignment = System.Windows.TextAlignment.Center;
txtblk1ShowStatus.FontWeight = FontWeights.Bold;
txtblk1ShowStatus.FontSize = 15;
txtblk1ShowStatus.FontStyle = FontStyles.Normal;
txtblk1ShowStatus.Padding = new Thickness(5, 10, 5, 10);
txtblk1ShowStatus.Text = param.Name;
Grid.SetColumn(txtblk1ShowStatus, 2);
Grid.SetRow(txtblk1ShowStatus, LoopCount);
childGrid.Children.Add(txtblk1ShowStatus);
rect.Child = childGrid;
Grid.SetRow(rect, LoopCount);
myGrid.Children.Add(rect);
There a bunch of things you need to consider here..
In case you want a Horizontally expanding smallGrid, set the
sp.Orientation=Orientation.Horizontal
Then set the widths of the columns in smallGrid to Auto.
colDef.Width = new GridLength(1, GridUnitType.Auto); // Auto
You don't really need the myGrid, directly using the Border should suffice.
Get rid of assigning the Height s eg:
rect.Width = g.Width;
rect.Height = g.Height;
childGrid.Height = sp.Height;
Else, if you wanted a vertically expanding smallGrid, make sure the parent of the Border rect (or myGrid, in case you decide to keep it), allows for expansion Height (mostly check that height is not hard coded to a fix number or something)
Also, set the
smallGrid.ShowGridLines = true;
to give you a better idea in regards to what is actually taking up the space.
Lastly, do this too
int totalRows = p.Parameter.Count() + p.Separator.Count();
for (int i = 0; i < totalRows; i++)
{
var rowDef=new RowDefinition();
rowdef.Height = new GridLength(1, GridUnitType.Auto);
myGrid.RowDefinitions.Add(rowDef);
}

only the first listpicker opens windows phone

I am using Windows Phone Toolkit - Nov 2011 (7.1 SDK) and I want to display multiple listpickers each
within a grid and each grid in a listbox. The problem is, only the first listpicker pops open and the rest don't. secondly how do I customize the full mode page of the listpicker to be displayed exclusively in Landscape orientation and set the page's "shell:SystemTray.IsVisible" to false.
Sorry I couldn't post a screenshot. error "Earn more than 10 reputation to post images".
Thanks
public MainPage()
{
InitializeComponent();
for (int g = 0; g < 10; g++)
{
// Define the margins template dor elements
Thickness elemThick = new Thickness();
// Create the Grid that will hold all the elements of a single entry
Grid entryGrd = new Grid();
entryGrd.VerticalAlignment = VerticalAlignment.Top;
entryGrd.HorizontalAlignment = HorizontalAlignment.Left;
elemThick.Left = 0;
elemThick.Bottom = 0;
elemThick.Right = 0;
elemThick.Top = 0;
entryGrd.Margin = elemThick;
entryGrd.Tag = lstbxPH.Items.Count;
// Setup the backgound value of the letBoder element
LinearGradientBrush elemLGB = new LinearGradientBrush();
elemLGB.EndPoint = new Point(0.5, 1);
elemLGB.StartPoint = new Point(0.5, 0);
GradientStop AquamarineGS = new GradientStop();
AquamarineGS.Color = Color.FromArgb(255, 127, 255, 212);
AquamarineGS.Offset = 0;
GradientStop greenLikeGS = new GradientStop();
greenLikeGS.Color = Color.FromArgb(255, 101, 250, 193);
greenLikeGS.Offset = 0.988;
elemLGB.GradientStops.Add(AquamarineGS);
elemLGB.GradientStops.Add(greenLikeGS);
// Draw the letter
for (int x = 0; x < 9; x++)
{
Border letBoder = new Border();
letBoder.Width = 53;
letBoder.Height = 51;
letBoder.VerticalAlignment = VerticalAlignment.Top;
letBoder.HorizontalAlignment = HorizontalAlignment.Left;
elemThick.Left = x * 60 + 71;
elemThick.Top = lstbxPH.Items.Count * 1 + 20;
letBoder.Margin = elemThick;
letBoder.Background = elemLGB;
// The Texblock
TextBlock let = new TextBlock();
let.VerticalAlignment = VerticalAlignment.Center;
let.HorizontalAlignment = HorizontalAlignment.Center;
let.FontSize = 25;
let.FontWeight = FontWeights.Bold;
let.Foreground = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255));
let.Text = x.ToString();
let.Tag = x;
letBoder.Child = let;
entryGrd.Children.Add(letBoder);
}
// Draw the List picker element for the draw types
ListPicker DType = new ListPicker();
DType.Width = 48;
DType.VerticalAlignment = VerticalAlignment.Top;
DType.HorizontalAlignment = HorizontalAlignment.Left;
DType.Background = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255));
DType.BorderBrush = new SolidColorBrush(Color.FromArgb(200, 255, 255, 255));
elemThick.Left = 17;
elemThick.Top = lstbxPH.Items.Count * 1 + 10;
DType.Margin = elemThick;
DType.FontSize = 18;
ListPickerItem item1 = new ListPickerItem() { Content = "A" };
ListPickerItem item2 = new ListPickerItem() { Content = "B" };
ListPickerItem item3 = new ListPickerItem() { Content = "C" };
DType.Items.Add(item1);
DType.Items.Add(item2);
DType.Items.Add(item3);
entryGrd.Children.Add(DType);
if (lstbxPH.Items.Count != 0)
{
// The delete button and related image
Button btnDel = new Button();
btnDel.Height = 65;
btnDel.Width = 60;
btnDel.Tag = lstbxPH.Items.Count;
btnDel.VerticalAlignment = VerticalAlignment.Top;
btnDel.HorizontalAlignment = HorizontalAlignment.Left;
btnDel.VerticalContentAlignment = VerticalAlignment.Top;
btnDel.HorizontalContentAlignment = HorizontalAlignment.Left;
elemThick.Left = 600;
elemThick.Top = lstbxPH.Items.Count + 13;
btnDel.Margin = elemThick;
elemThick.Left = 0;
elemThick.Bottom = 0;
elemThick.Right = 0;
elemThick.Top = 0;
btnDel.Name = "btnDel";
btnDel.Padding = elemThick;
btnDel.BorderBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
Image imgDel = new Image();
imgDel.Source = new BitmapImage(new Uri("/appbar.delete.rest.png", UriKind.RelativeOrAbsolute));
imgDel.VerticalAlignment = VerticalAlignment.Top;
imgDel.HorizontalAlignment = HorizontalAlignment.Left;
imgDel.Height = 35;
imgDel.Width = 30;
elemThick.Left = 0;
elemThick.Bottom = 0;
elemThick.Right = 0;
elemThick.Top = 0;
imgDel.Margin = elemThick;
imgDel.Stretch = Stretch.UniformToFill;
btnDel.Content = imgDel;
entryGrd.Children.Add(btnDel);
}
// Add the grid with to the list box
this.lstbxPH.Items.Add(entryGrd);
}
}
This issue was actually solved by the Windows Phone Toolkit - Nov 2011 (7.1 SDK).
Here is how I worked it out.
Download the November release of the toolkit http://silverlight.codeplex.com/releases/view/75888
if you had a previous release of the toolkit installed, please uninstall it and unreferenced the tool kit on you project
Install the November release of the toolkit
Reference the toolkit on your project, debug and boom! it woks.

Setting tooltip width and height dynamically

In WPF (C#) is there a way to set the tooltip's height and width dynamically (meaning in code). Thanks for the help.
System.Windows.Controls.Image td = new System.Windows.Controls.Image();
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(Directory.GetCurrentDirectory() + "/Homepage.jpg");
td.Width = 530;
td.Height = 392;
//myBitmapImage.DecodePixelWidth = 430;
//myBitmapImage.DecodePixelHeight = 292;
myBitmapImage.EndInit();
td.Source = myBitmapImage;
TextBlock textBlock = new TextBlock();
BrushConverter conv = new BrushConverter();
string strColor1 = bannerColor.SelectedItem.ToString();
strColor1 = strColor1.Substring(strColor1.IndexOf(' ') + 1);
SolidColorBrush col = conv.ConvertFromString(strColor1) as SolidColorBrush;
textBlock.Foreground = col;
textBlock.FontWeight = FontWeights.Bold;
textBlock.FontSize = 18;
textBlock.FontFamily = new System.Windows.Media.FontFamily("Tahoma");
textBlock.Width = 100;
textBlock.Height = 20;
textBlock.Text = "BACKUP";
textBlock.Margin = new Thickness(5, 5, 425, 367);
Grid toolTipPanel = new Grid();
toolTipPanel.Width = 530;
toolTipPanel.Height = 392;
toolTipPanel.Children.Add(td);
toolTipPanel.Children.Add(textBlock);
ToolTipService.SetToolTip(image1, toolTipPanel);
ToolTipService.SetShowDuration(image1, 999999999);`
In your code just set the tooltip's height and width property to Double.NaN to have the width and height adjust dynamically.
_toolTip.Width = Double.NaN;
_toolTip.Height = Double.NaN;
This will do the trick.
A tool tip's height and width are based on its content. So you should simply make the content the size you want it to be.
Perhaps you could post your code that sets the tool tip, for further clarification?

Categories

Resources