Rich TextBlock in ListViewItem Text Wrapping - xaml

I have a RichTextBlock in a ListViewItem in a ListView. I can't for the life of me findout why the text wrapping on the RichTextBlock won't apply.
XAML:
<ScrollViewer x:Name="MessagesScroller" HorizontalScrollMode="Disabled">
<ListView x:Name="Messages" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>
</ScrollViewer>
C#
ListViewItem listviewitem = new ListViewItem();
listviewitem.HorizontalContentAlignment = HorizontalAlignment.Stretch;
listviewitem.VerticalAlignment = VerticalAlignment.Stretch;
listviewitem.Tag = message.Id;
StackPanel stack = new StackPanel();
stack.Orientation = Orientation.Horizontal;
stack.VerticalAlignment = VerticalAlignment.Stretch;
Image Avatar = new Image();
Avatar.Height = 50;
Avatar.VerticalAlignment = VerticalAlignment.Top;
Avatar.Source = new BitmapImage(new Uri("https://cdn.discordapp.com/avatars/" + message.User.Id + "/" + message.User.Avatar + ".jpg"));
stack.Children.Add(Avatar);
StackPanel innerstack = new StackPanel();
innerstack.VerticalAlignment = VerticalAlignment.Stretch;
StackPanel MsgData = new StackPanel();
MsgData.Orientation = Orientation.Horizontal;
#region RichTextBlock
RichTextBlock user = new RichTextBlock();
user.TextWrapping = TextWrapping.WrapWholeWords;
Paragraph userPara = new Paragraph();
Run run1 = new Run();
run1.Text = message.User.Username;
userPara.Inlines.Add(run1);
user.Blocks.Add(userPara);
#endregion
MsgData.Children.Add(user);
#region RichTextBlock
RichTextBlock timestamp = new RichTextBlock();
Paragraph timePara = new Paragraph();
Run run2 = new Run();
run2.Text = message.Timestamp.Month.ToString() + "/" + message.Timestamp.Day + " at " + message.Timestamp.Hour.ToString() + ":";
if (message.Timestamp.Minute < 9)
{
run2.Text += "0";
}
run2.Text += message.Timestamp.Minute.ToString();
timestamp.Foreground = GetSolidColorBrush("#FF333333");
timePara.Inlines.Add(run2);
timestamp.Blocks.Add(timePara);
timestamp.Margin = new Thickness(5, 0, 0, 0);
#endregion
MsgData.Children.Add(timestamp);
innerstack.Children.Add(MsgData);
#region RichTextBlock
RichTextBlock txtblock = new RichTextBlock();
txtblock.TextWrapping = TextWrapping.WrapWholeWords;
Paragraph txtPara = new Paragraph();
Run run3 = new Run();
run3.Text = message.Content;
txtPara.Inlines.Add(run3);
txtblock.Blocks.Add(txtPara);
foreach (SharedModels.Embed embed in message.Embeds)
{
Paragraph paragraph = new Paragraph();
if (embed.title != null)
{
Run title = new Run();
title.Text = embed.title + "\n";
paragraph.Inlines.Add(title);
}
if (embed.Description != null)
{
Run desc = new Run();
desc.Text = embed.Description + "\n";
paragraph.Inlines.Add(desc);
}
if (embed.Thumbnail.Url != null)
{
InlineUIContainer container = new InlineUIContainer();
BitmapImage bi = new BitmapImage(new Uri(embed.Thumbnail.ProxyUrl));
Image image = new Image();
image.Height = 300;
image.Source = bi;
container.Child = image;
paragraph.Inlines.Add(container);
}
txtblock.Blocks.Add(paragraph);
}
foreach (SharedModels.Attachment attach in message.Attachments)
{
Paragraph paragraph = new Paragraph();
Run run = new Run();
run.Text = attach.Filename;
BitmapImage bi = new BitmapImage(new Uri(attach.Url));
Image image = new Image();
image.Height = 300;
image.Source = bi;
InlineUIContainer container = new InlineUIContainer();
container.Child = image;
paragraph.Inlines.Add(run);
paragraph.Inlines.Add(container);
txtblock.Blocks.Add(paragraph);
}
#endregion
innerstack.Children.Add(txtblock);
stack.Children.Add(innerstack);
listviewitem.Content = stack;
#region Flyout
Flyout flyout = new Flyout();
StackPanel flyoutcontent = new StackPanel();
flyoutcontent.Margin = new Thickness(-10);
/*Button AddRection = new Button()
{
Content = "Add Reaction",
HorizontalAlignment = HorizontalAlignment.Stretch
};
flyoutcontent.Children.Add(AddRection);
Button Pin = new Button()
{
Content = "Pin",
HorizontalAlignment = HorizontalAlignment.Stretch
};
flyoutcontent.Children.Add(Pin);*/
/*Button Edit = new Button()
{
Content = "Edit",
HorizontalAlignment = HorizontalAlignment.Stretch,
Tag = message.Id
};
Edit.Click += EditMessage;
flyoutcontent.Children.Add(Edit);*/
Button Delete = new Button()
{
Content = "Delete",
HorizontalAlignment = HorizontalAlignment.Stretch,
Tag = message.Id
};
Delete.Click += DeleteThisMessage;
flyoutcontent.Children.Add(Delete);
flyout.Content = flyoutcontent;
listviewitem.ContextFlyout = flyout;
listviewitem.RightTapped += OpenRightTapFlyout;
listviewitem.Holding += OpenHoldingFlyout;
#endregion
Messages.Items.Add(listviewitem);
I have uprooted my entire program to use StackPanels instead but that didn't help

You used StackPanel for your layout and set the Orientation property to Horizontal for the StackPanel. StackPanel is size to its children. So it seems like the reason is that you don't set the Width property for the RichTextBlock. The width of RichTextBlock size to its content, StackPanelsize toRichTextBlock`, it may not wrap.
You may have several ways to resolve this:
Set width property for the RichTextBlock.
RichTextBlock txtblock = new RichTextBlock();
txtblock.Width = 300;
txtblock.TextWrapping = TextWrapping.WrapWholeWords;
Remove the orientation property for the StackPanel if you don't need such a layout.
//stack.Orientation = Orientation.Horizontal;
Or you may use a Grid instead. Grid may better help you define the layout. You may define the image and RichTextBlock layout as followings.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Source="Assets/caffe1.jpg" Height="100" Grid.Row="0" Grid.Column="0"></Image>
<RichTextBlock TextWrapping="WrapWholeWords" Grid.Row="0" Grid.Column="1">
<Paragraph>
<Run FontStyle="Italic">sample text todemonstrate some properties.demonstrate some properties.demonstrate some properties.demonstrate some properties.
demonstrate some properties.demonstrate some properties.demonstrate some properties.demonstrate some properties.demonstrate some properties.
</Run>
</Paragraph>
</RichTextBlock>
</Grid>

Related

Create multiple frames in code behind in Xamarin.Forms

I want to create multiple frames in code-behind, but when creating frames in loop and adding elements in content, only one frame has all elements and other frames are empty! why?
My code is:
private void searchResults_ItemTapped(object sender, ItemTappedEventArgs e)
{
searchResults.IsVisible = false;
Indexes Indexes = (Indexes)searchResults.SelectedItem;
_viewModel.Items.Add(db.RequestToJson(Indexes.Index));
searchbar.Text = string.Empty;
StackLayout Words = new StackLayout();
StackLayout WordDetail = new StackLayout();
foreach (var dt in _viewModel.Items)
{
AddTextToLabel(nameof(dt.Word), dt.Word, WordDetail);
var BaseLang = dt.BaseLang;
AddTextToLabel(nameof(BaseLang.Meaning), BaseLang.Meaning, WordDetail);
Words.Children.Add(new Frame { BackgroundColor = Color.FromHex("2196F3"), Padding = 5, HasShadow = false, Margin = new Thickness(10, 10, 80, 10), Content = new StackLayout { Children = { WordDetail } } });
}
SearchResult.Content = Words;
SearchResult.IsVisible = true;
}
private void AddTextToLabel(string title, string data, StackLayout worddetail)
{
worddetail.Children.Add(new Label { Text = title + ":", FontAttributes = FontAttributes.Bold, TextColor = Color.White });
worddetail.Children.Add(new Label { Text = data, TextColor = Color.White });
}
And here is the result:
you are using the same instance of WordDetail in every iteration of the loop
instead, create a new instance each time
foreach (var dt in _viewModel.Items)
{
StackLayout WordDetail = new StackLayout();
I reproduced your situation locally by copying your code. I solved it by moving the WordDetail declaration inside the foreach like so:
StackLayout Words = new StackLayout();
foreach (var dt in _viewModel.Items)
{
StackLayout WordDetail = new StackLayout();
AddTextToLabel(nameof(dt.Word), dt.Word, WordDetail);
var BaseLang = dt.BaseLang;
AddTextToLabel(nameof(BaseLang.Meaning), BaseLang.Meaning, WordDetail);
Words.Children.Add(new Frame { BackgroundColor = Color.FromHex("2196F3"), Padding = 5, HasShadow = false, Margin = new Thickness(10, 10, 80, 10), Content = new StackLayout { Children = { WordDetail } } });
}

Xamarin - XAML Grid UI overwriting on each other

I am creating a UI using a grid in Xamarin which I have put in StackLayout.
Below is the following code for xaml.
program.xaml
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LoginPage.Page">
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<StackLayout BackgroundColor="#3a4851">
<Label Text="Identifications" TextColor="White" FontSize="15" Margin="10" />
</StackLayout>
<StackLayout>
<Grid x:Name="identificationGridLayout" HorizontalOptions="Center"></Grid>
</StackLayout>
<StackLayout BackgroundColor="#3a4851">
<Label Text="Deciles" TextColor="White" FontSize="15" Margin="10" />
</StackLayout>
<StackLayout>
<Grid x:Name="decileGridLayout" HorizontalOptions="Center"></Grid>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
I am creating the Grid header and data programatically.
program.cs
public partial class Page : ContentPage
{
private LoadingPopUp popUp;
private Repository repository = new Repository();
private JObject jResult;
private List<string> rowHeader;
private List<PrescriberIdentitifcation> prescriberIdentificationValue;
private List<PrescriberDecile> prescriberDecileValue;
public Page() { InitializeComponent(); }
public Page(string guid)
{
InitializeComponent();
FetchDataForDetail(guid);
}
async void FetchDataForDetail(string guid)
{
try
{
popUp = new LoadingPopUp("Loading data ...");
await PopupNavigation.PushAsync(popUp);
//Get Identification Data for prescriber
JObject identificationResult = await GetRepositoryDetailData(guid);
var identificationdata = JsonConvert.DeserializeObject<PrescriberIdentificationList>(identificationResult.ToString());
prescriberIdentificationValue = identificationdata.value;
int index = 0;
foreach (var obj in identificationResult["value"])
{
prescriberIdentificationValue[index].vcm_type_name = (string)obj["vcm_type#OData.Community.Display.V1.FormattedValue"];
index++;
}
drawIdentificationGrid();
//Get Deciles Data for prescriber
JObject decileResult = await GetRepositoryDetailData(guid);
var deciledata = JsonConvert.DeserializeObject<PrescriberIdentificationList>(decileResult.ToString());
prescriberIdentificationValue = deciledata.value;
Debug.WriteLine("data prescriberIdentificationValue : " + prescriberIdentificationValue);
drawDecilesGrid();
await PopupNavigation.PopAllAsync();
}
catch (Exception ex) {
Debug.WriteLine("error in identification loading : " + ex.Message);
await PopupNavigation.PopAllAsync();
}
}
public async Task<JObject> GetRepositoryDetailData(string guid, string entity, string filter)
{
try
{
jResult = await repository.Retrieve(GlobalVariables.AuthToken, entity, filter + guid);
return jResult;
}
catch (Exception err)
{
Debug.WriteLine(err.Message);
await PopupNavigation.PopAllAsync();
await DisplayAlert("Error", "Oops something went wrong", "Ok");
}
return jResult;
}
void drawIdentificationGrid()
{
try
{
rowHeader = new List<string>{"Type", "Number", "License State", "Sampleability","Expiration Date","License Status" };
drawGridHeader(identificationGridLayout,1, rowHeader.Count,rowHeader);
for (int rowIndex = 1; rowIndex <= prescriberIdentificationValue.Count; rowIndex++)
{
var datatypeLabel = new Label { Text = prescriberIdentificationValue[rowIndex-1].vcm_type_name.ToString(),FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
var datanumberLabel = new Label { Text = prescriberIdentificationValue[rowIndex-1].vcm_name.ToString(),FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
var datalicenseStateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex-1]._vcm_licensestate_value != null) ? prescriberIdentificationValue[rowIndex-1]._vcm_licensestate_value : "-" , FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
var datasampleabiltiyLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1].vcm_sampleability == false) ? "No": "Yes", FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
var dataexpirationDateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex-1].vcm_expirationdate != null) ? prescriberIdentificationValue[rowIndex-1].vcm_expirationdate : "-", FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
Debug.WriteLine("data datatypeLabel {0} datanumberLabel {1} datalicenseStateLabel {2} datasampleabiltiyLabel {3} dataexpirationDateLabel {4} rowIndex {5}",datatypeLabel.Text,datanumberLabel.Text,datalicenseStateLabel.Text, datasampleabiltiyLabel.Text, dataexpirationDateLabel.Text, rowIndex);
identificationGridLayout.Children.Add(datatypeLabel, 0, rowIndex);
identificationGridLayout.Children.Add(datanumberLabel, 1, rowIndex);
identificationGridLayout.Children.Add(datalicenseStateLabel, 2, rowIndex);
identificationGridLayout.Children.Add(datasampleabiltiyLabel, 3, rowIndex);
identificationGridLayout.Children.Add(dataexpirationDateLabel, 4, rowIndex);
}
}
catch (Exception ex) { Debug.WriteLine("Error in drawing Identifications: "+ ex.Message);}
}
void drawDecilesGrid()
{
try
{
rowHeader = new List<string>{"Quarter", "Decile Type", "Decile", "Rank","Organization Type" };
drawGridHeader(decileGridLayout,1, rowHeader.Count, rowHeader);
//for (int rowIndex = 1; rowIndex <= prescriberIdentificationValue.Count; rowIndex++)
//{
// var datatypeLabel = new Label { Text = prescriberIdentificationValue[rowIndex - 1].vcm_type_name.ToString(), FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
// var datanumberLabel = new Label { Text = prescriberIdentificationValue[rowIndex - 1].vcm_name.ToString(), FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
// var datalicenseStateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1]._vcm_licensestate_value != null) ? prescriberIdentificationValue[rowIndex - 1]._vcm_licensestate_value : "-", FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
// var datasampleabiltiyLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1].vcm_sampleability == false) ? "No" : "Yes", FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
// var dataexpirationDateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1].vcm_expirationdate != null) ? prescriberIdentificationValue[rowIndex - 1].vcm_expirationdate : "-", FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
// Debug.WriteLine("data datatypeLabel {0} datanumberLabel {1} datalicenseStateLabel {2} datasampleabiltiyLabel {3} dataexpirationDateLabel {4} rowIndex {5}",datatypeLabel.Text,datanumberLabel.Text,datalicenseStateLabel.Text, datasampleabiltiyLabel.Text, dataexpirationDateLabel.Text, rowIndex);
// identificationGridLayout.Children.Add(datatypeLabel, 0, rowIndex);
// identificationGridLayout.Children.Add(datanumberLabel, 1, rowIndex);
// identificationGridLayout.Children.Add(datalicenseStateLabel, 2, rowIndex);
// identificationGridLayout.Children.Add(datasampleabiltiyLabel, 3, rowIndex);
// identificationGridLayout.Children.Add(dataexpirationDateLabel, 4, rowIndex);
//}
}
catch (Exception ex) { Debug.WriteLine("Error in drawing Identifications: "+ ex.Message);}
}
void drawGridHeader(Grid gridLayout, int rowIndexLength, int columnIndexLength, List<string> rowHeaders)
{
try
{
gridLayout.RowDefinitions = new RowDefinitionCollection();
gridLayout.ColumnDefinitions = new ColumnDefinitionCollection();
for (int rowIndex = 0; rowIndex < rowIndexLength; rowIndex++)
{
gridLayout.RowDefinitions.Add(new RowDefinition());
}
for (int columnIndex = 0; columnIndex <= columnIndexLength; columnIndex++)
{
gridLayout.ColumnDefinitions.Add(new ColumnDefinition());
}
for (int i = 0; i < columnIndexLength; i++)
{
var label = new Label { Text = rowHeaders[i], FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
identificationGridLayout.Children.Add(label, i, 0);
}
}
catch (Exception ex) { Debug.WriteLine("Error in drawing grid header: "+ ex.Message);}
}
}
}
drawGridHeader() is common to creating Header for different grids. Data for the cell is passed in different functions and grid reference is passed to it.
Ex: -
rowHeader = new List<string>{"Quarter", "Decile Type", "Decile", "Rank","Organization Type" };
drawGridHeader(decileGridLayout,1, rowHeader.Count, rowHeader);
But after fetching the data, The Grid is over writing on each other.
I tried creating manual grid with row item and they are stacking properly in order but when programmatically doing it, grid is stacking upon each other.
It should been below the Label Decile.
Inside the last for-loop in drawGridHeader(), you're not referencing the passed in grid when adding the labels:
for (int i = 0; i < columnIndexLength; i++)
{
var label = new Label { Text = rowHeaders[i], FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
// This references the wrong Grid
// identificationGridLayout.Children.Add(label, i, 0);
gridLayout.Children.Add(label, i, 0);
}

Custom Slider Windows 8.1

i need to create a custom slider, at the moment my slider looks exactly how i want, it looks like this (image from VisualStudio):
ant the xaml code is this:
<Grid x:Name="mainGrid">
<Grid Height="240" Width="300" Canvas.ZIndex="2">
<Grid.RenderTransform>
<RotateTransform x:Name="rotateTransform"
Angle="-125"
CenterX="150"
CenterY="150" />
</Grid.RenderTransform>
<Ellipse Height="54" Width="54"
x:Name="knob"
Fill="Red"
PointerMoved="Image_PointerMoved"
VerticalAlignment="Top"
Margin="0,-7,0,0"/>
</Grid>
<Path x:Name="path"
Data="M269.01,233.229 C303.532,181.303 304.261,118.855 269.097,67.0139 C207.933,-15.2077 92.8603,-16.8742 31.2108,66.0937 C-3.68835,121.514 -3.36331,179.271 30.8461,232.917 C51.2571,253.282 74.8965,230.573 61.3585,209.167 C38.2919,172.761 36.0008,129.688 62.1396,90.2093 C106.398,28.022 194.916,29.4803 237.509,90.1399 C262.554,127.345 263.613,170.209 237.647,209.792 C227.355,233.49 250.474,250.782 269.01,233.229 z"
Stretch="Fill"
Fill="Gray" />
</Grid>
and the C# code is this:
private void Image_PointerMoved(object sender, PointerRoutedEventArgs e)
{
//Canculate the current rotation angle and set the value.
var newPos = e.GetCurrentPoint(path);
double angle = GetAngleR(newPos.Position);
rotateTransform.Angle = angle;
}
public double GetAngleR(Point pos)
{
var xDiff = 150 - pos.X;
var yDiff = 150 - pos.Y;
var r = Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff));
var radians = Math.Acos((yDiff) / r);
var angle = radians * (180 / Math.PI);
if(angle > 125)
{
angle = 125;
}
if(pos.X < 150)
{
angle = -angle;
}
return angle;
}
my problem is how i fill the path with a different color as i move the ellipse?
i need to achive somethig like this:
any suggestion?
Ok I have figured out how to do this slider, this isn't a perfect solution but it works and for me is enough.
I have created a GeometryGroup that contains some BezierSegment used to draw the arch path and then I have added a to the group a RectangleGeometry that is the size of the element.
With GeometryGroup in this case, the intersecting area of two shapes is not filled.
After that i have placed the right color behind the main path.
this is the code:
XAML
<Grid x:Name="mainGrid">
<Grid Height="240" Width="300" Canvas.ZIndex="2">
<Grid.RenderTransform>
<RotateTransform x:Name="rotateTransform"
Angle="-125"
CenterX="150"
CenterY="150" />
</Grid.RenderTransform>
<Image Height="54" Width="54" x:Name="knob"
Source="ms-appx:///Assets/ic_slider_credito.png"
PointerMoved="Image_PointerMoved"
VerticalAlignment="Top"
Margin="0,-5,0,0" />
</Grid>
<Rectangle VerticalAlignment="Top"
HorizontalAlignment="Left"
Fill="Gray"
Width="300"
Height="240" />
<Path x:Name="fillPath"
Height="240"
Width="300"
UseLayoutRounding="False"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Fill="Orange" />
<Path x:Name="path"
Height="240"
Width="300"
UseLayoutRounding="False"
Stretch="Fill"
Fill="White" />
</Grid>
C#
public SliderInvioCredito()
{
this.InitializeComponent();
DrawPath();
}
private void Image_PointerMoved(object sender, PointerRoutedEventArgs e)
{
var newPos = e.GetCurrentPoint(path);
double angle = GetAngleR(newPos.Position);
rotateTransform.Angle = angle;
}
public double GetAngleR(Point pos)
{
var xDiff = 150 - pos.X;
var yDiff = 150 - pos.Y;
var r = Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff));
var radians = Math.Acos((yDiff) / r);
var angle = radians * (180 / Math.PI);
if (angle > 125)
{
angle = 125;
}
if (pos.X < 150)
{
angle = -angle;
}
DrawFillPath(pos.X, pos.Y, angle);
return angle;
}
private void DrawFillPath(double x, double y, double angle)
{
var start = new Point(150, 120);
var pth = new PathFigure();
pth.StartPoint = start;
var ls1 = new LineSegment();
ls1.Point = start;
pth.Segments.Add(ls1);
var ls8 = new LineSegment();
ls8.Point = new Point(150, 240);
pth.Segments.Add(ls8);
var ls2 = new LineSegment();
ls2.Point = new Point(0, 240);
pth.Segments.Add(ls2);
if (angle > -45)
{
var ls5 = new LineSegment();
ls5.Point = new Point(0, 0);
pth.Segments.Add(ls5);
if (angle > -30)
{
var ls6 = new LineSegment();
ls6.Point = new Point(x, 0);
pth.Segments.Add(ls6);
}
}
else
{
var ls3 = new LineSegment();
ls3.Point = new Point(0, y);
pth.Segments.Add(ls3);
}
if (angle > 45)
{
var ls7 = new LineSegment();
ls7.Point = new Point(300, 0);
pth.Segments.Add(ls7);
var ls9 = new LineSegment();
ls9.Point = new Point(300, y);
pth.Segments.Add(ls9);
}
var ls4 = new LineSegment();
ls4.Point = new Point(x, y);
pth.Segments.Add(ls4);
var pthCollection = new PathFigureCollection();
pthCollection.Add(pth);
var pthGeometry = new PathGeometry();
pthGeometry.Figures = pthCollection;
fillPath.Data = pthGeometry;
}
private void DrawPath()
{
var cc1 = new BezierSegment();
cc1.Point1 = new Point(303.532, 181.303);
cc1.Point2 = new Point(304.261, 118.855);
cc1.Point3 = new Point(269.097, 67.0139);
var cc2 = new BezierSegment();
cc2.Point1 = new Point(207.933, -15.2077);
cc2.Point2 = new Point(92.8603, -16.8742);
cc2.Point3 = new Point(31.2108, 66.0937);
var cc3 = new BezierSegment();
cc3.Point1 = new Point(-3.68835, 121.514);
cc3.Point2 = new Point(-3.36331, 179.271);
cc3.Point3 = new Point(30.8461, 232.917);
var cc4 = new BezierSegment();
cc4.Point1 = new Point(51.2571, 253.282);
cc4.Point2 = new Point(74.8965, 230.573);
cc4.Point3 = new Point(61.3585, 209.167);
var cc5 = new BezierSegment();
cc5.Point1 = new Point(38.2919, 172.761);
cc5.Point2 = new Point(36.0008, 129.688);
cc5.Point3 = new Point(62.1396, 90.2093);
var cc6 = new BezierSegment();
cc6.Point1 = new Point(106.398, 28.022);
cc6.Point2 = new Point(194.916, 29.4803);
cc6.Point3 = new Point(237.509, 90.1399);
var cc7 = new BezierSegment();
cc7.Point1 = new Point(262.554, 127.345);
cc7.Point2 = new Point(263.613, 170.209);
cc7.Point3 = new Point(237.647, 209.792);
var cc8 = new BezierSegment();
cc8.Point1 = new Point(227.355, 233.49);
cc8.Point2 = new Point(250.474, 250.782);
cc8.Point3 = new Point(269.01, 233.229);
var pthFigure = new PathFigure();
pthFigure.StartPoint = new Point(269.01, 233.229);
var psc = new PathSegmentCollection();
psc.Add(cc1);
psc.Add(cc2);
psc.Add(cc3);
psc.Add(cc4);
psc.Add(cc5);
psc.Add(cc6);
psc.Add(cc7);
psc.Add(cc8);
pthFigure.Segments = psc;
var pthFigureCollection = new PathFigureCollection();
pthFigureCollection.Add(pthFigure);
var pthGeometry = new PathGeometry();
pthGeometry.Figures = pthFigureCollection;
var rect = new RectangleGeometry();
rect.Rect = new Rect(0, 0, 300, 240);
var gg = new GeometryGroup();
gg.Children.Add(pthGeometry);
gg.Children.Add(rect);
path.Data = gg;
}

Not enough quota is available to process this command. (Exception from HRESULT: 0x80070718) in windows 8 metro app for GRID(Not for GRIDVIEW)

I am trying to generate dynamic controls in grid through UI where am dynamically specifying the size of controls. while generating more then 1500 control it is throwing this error "Not enough quota is available to process this command. (Exception from HRESULT: 0x80070718) " . i have seen some solution for gridview for the same exception but i am using GRID so not beneficial for me .
please let me know.
Thanks in advance.
<ScrollViewer HorizontalScrollMode="Auto"
HorizontalScrollBarVisibility="Auto"
VerticalScrollMode="Auto"
VerticalScrollBarVisibility="Auto" Margin="232,10,267,0" Grid.Row="1">
<Grid Name="dynamicgrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightBlue" Height="Auto" Width="Auto" Grid.Row="1"/>
</ScrollViewer>
C# code
try
{
MainPage mainpage = (MainPage)e.Parameter;
buttons = Convert.ToInt32(mainpage.buttonsize);
textblock = Convert.ToInt32(mainpage.txtBlocksize);
textbox = Convert.ToInt32(mainpage.txtBoxsize);
rows = Convert.ToInt32(mainpage.rows);
buttonwidth = Convert.ToInt32(mainpage.buttonwidth);
textblockwidth = Convert.ToInt32(mainpage.txtBlockwidth);
textboxwidth = Convert.ToInt32(mainpage.txtBoxwidth);
grdcolumn = buttons + textblock + textbox;
for (int i = 0; i < rows; i++)
{
RowDefinition rowDef = new RowDefinition();
rowDef.Height = new GridLength(200, GridUnitType.Auto);
dynamicgrid.RowDefinitions.Add(rowDef);
}
for (int j = 0; j < grdcolumn; j++) //need to mention
{
ColumnDefinition colDef1 = new ColumnDefinition();
colDef1.Width = new GridLength(100, GridUnitType.Auto);
dynamicgrid.ColumnDefinitions.Add(colDef1);
}
for (textboxcolumncount = 0; textboxcolumncount < textbox; textboxcolumncount++)
{
for (int i = 0; i < rows; i++)//textbox
{
TextBox txtbox = new TextBox();
txtbox.SetValue(TextBox.TextProperty, "txtbox" + i.ToString());
txtbox.Width = textboxwidth;
txtbox.Height = 50;
txtbox.SetValue(Grid.ColumnProperty, textboxcolumncount);
txtbox.SetValue(Grid.RowProperty, i);
dynamicgrid.Children.Add(txtbox);
dynamicgrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
}
}
textboxcolumncount = textbox;
for (textblockcolumncount = textboxcolumncount; textblockcolumncount < (grdcolumn - (buttons)); textblockcolumncount++)
{
for (int i = 0; i < rows; i++)
{
TextBlock txtblock = new TextBlock();
txtblock.SetValue(TextBlock.NameProperty, "txtblock" + i.ToString());
txtblock.Width = textblockwidth;
txtblock.Height = 50;
txtblock.SetValue(Grid.ColumnProperty, textblockcolumncount);
txtblock.SetValue(Grid.RowProperty, i);
txtblock.Text = "TextBlock" + i.ToString();
txtblock.Foreground = new SolidColorBrush(Colors.Black);
dynamicgrid.Children.Add(txtblock);
dynamicgrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
}
}
textboxcolumncount = textblockcolumncount;
for (buttonCoulmncount = textboxcolumncount; buttonCoulmncount < (grdcolumn); buttonCoulmncount++)
{
for (int i = 0; i < rows; i++) //button
{
Button btn = new Button();
btn.SetValue(Button.NameProperty, "btn" + i.ToString());
btn.Content = "Button" + i.ToString();
btn.Width = textboxwidth;
btn.Height = 50;
btn.Foreground = new SolidColorBrush(Colors.Black);
btn.SetValue(Grid.RowProperty, i);
btn.SetValue(Grid.ColumnProperty, buttonCoulmncount);
dynamicgrid.Children.Add(btn);
dynamicgrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
}
}
}
catch (Exception ex)
{
throw ex;
}
Go through this Link I am not sure wether this will solve your problem or you will have an idea of it.
Not enough quota ex
After that you can make a search. I still have not found any issue like this. Guess have to Replicate the code on the system. :)

WP7: LayoutTransform a ListBoxItem

Here's my XAML:
<ListBox x:Name="MyListBox" FontSize="40"
SelectionChanged="MyListBox_SelectionChanged">
</ListBox>
In this code-behind (below), I am attempting to animate a delete action. When the item is selected I delete it. I visually animate it with a ScaleTransform. In WPF I would use a LayoutTransform, but since I only have RenderTransform in WP/SL, I am using RenderTransform - and as a result the surrounding layout is not responding to the change in size. The record is still correctly deleted, but the visual effect is diminished.
Is there a way to do this in WP? Is there a way to resize a ListBoxItem so that the surrounding content responds?
ObservableCollection<string> m_Data;
public MainPage()
{
InitializeComponent();
m_Data = new ObservableCollection<string>
{ "One", "Two", "Three", "Four" };
MyListBox.ItemsSource = m_Data;
}
private void MyListBox_SelectionChanged(object sender,
SelectionChangedEventArgs e)
{
// fetch ListBoxItem
if (e.AddedItems.Count == 0)
return;
var _Data = e.AddedItems[0] as string;
var _Item = MyListBox.ItemContainerGenerator
.ContainerFromItem(_Data) as ListBoxItem;
// setup to resize using scale transform
var _Scale = new ScaleTransform
{
CenterX = _Item.RenderSize.Width / 2,
CenterY = _Item.RenderSize.Height / 2,
ScaleX = .99,
ScaleY = .99
};
_Item.RenderTransform = _Scale;
// setup storyboard
var _Story = new Storyboard();
_Story.Completed += (s, e1) =>
{
// remove data from collection
m_Data.Remove(_Data);
};
// animate scale X
var _AnimationX = new DoubleAnimation
{
To = .01,
Duration = TimeSpan.FromSeconds(2),
};
_Story.Children.Add(_AnimationX);
Storyboard.SetTarget(_AnimationX, _Scale);
Storyboard.SetTargetProperty(_AnimationX,
new PropertyPath(ScaleTransform.ScaleXProperty));
// animate scale Y
var _AnimationY = new DoubleAnimation
{
To = .01,
Duration = TimeSpan.FromSeconds(2),
};
_Story.Children.Add(_AnimationY);
Storyboard.SetTarget(_AnimationY, _Scale);
Storyboard.SetTargetProperty(_AnimationY,
new PropertyPath(ScaleTransform.ScaleYProperty));
_Story.Begin();
}
You can also use LayoutTransform on Windows Phone so I would just use that. .