I'm trying to combine two rectangles that I need to create dynamically but I can't figure out how to draw them using .Data and I don't know how to convert from Windows.Shapes.Rectangle to Windows.Media.Geometry.
Rectangle Cross1 = new Rectangle();
Cross1.Margin = new Thickness(465, -140, 0, 0);
Cross1.Height = 110;
Cross1.Width = 15;
Cross1.RenderTransform = rotateTransform1;
Rectangle Cross2 = new Rectangle();
Cross2.HorizontalAlignment = HorizontalAlignment.Left;
Cross2.VerticalAlignment = VerticalAlignment.Top;
Cross2.Margin = new Thickness(362, -103, 0, 0);
Cross2.Height = 110;
Cross2.Width = 15;
Cross2.RenderTransform = rotateTransform2;
CombinedGeometry c1 = new CombinedGeometry(GeometryCombineMode.Union, Cross1, Cross2);
The CombinedGeometry class only works with other System.Windows.Media.Geometry objects, not System.Windows.Shapes. You need to use the equivalent RectangleGeometry class instead.
Something such as:
RectangleGeometry Cross1 = new RectangleGeometry(new Rect(0, 0, 15, 110));
Cross1.Transform = rotateTransform1;
RectangleGeometry Cross2 = new RectangleGeometry(new Rect(0, 0, 15, 110));
Cross2.Transform = rotateTransform2;
CombinedGeometry c1 = new CombinedGeometry(GeometryCombineMode.Union, Cross1, Cross2);
Related
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 =)
I'm having trouble changing the font and fontsize of a placeholder inside a UITextField.
this.emailTextField = new UITextField ();
//Not working
this.emailTextField.AttributedPlaceholder = new NSAttributedString ("Email address", UIFont.FromName("Didot-Italic", 6.0f));
this.emailTextField.KeyboardType = UIKeyboardType.EmailAddress;
this.emailTextField.ReturnKeyType = UIReturnKeyType.Next;
this.emailTextField.AdjustsFontSizeToFitWidth = true;
this.emailTextField.ClearButtonMode = UITextFieldViewMode.Always;
this.emailTextField.BackgroundColor = UIColor.White;
this.emailTextField.BorderStyle = UITextBorderStyle.None;
var bottomLayer = new CALayer ();
bottomLayer.BorderColor = UIColor.Black.CGColor;
bottomLayer.BorderWidth = 1;
bottomLayer.Frame = new RectangleF (0, 29, 200, 1);
this.emailTextField.Layer.AddSublayer (bottomLayer);
this.emailTextField.Frame = new RectangleF (60, this.fbButton.Frame.Bottom + 20, 200, 30);
You could try to use it like below. It worked me so far.
this.emailTextField.AttributedPlaceholder = new NSAttributedString ("Email address", new UIStringAttributes{Font = UIFont.FromName("Didot-Italic", 6.0f)});
I am trying to create a 50 x 50 square that has half of the rectangle white and the other half black (the lines going vertically instead of horizontally). I have the following code, but it is not filling the rectangle as expected. How do I make it 50% white and 50% black?
System.Windows.Shapes.Rectangle swatch = new System.Windows.Shapes.Rectangle();
swatch.Width = 50;
swatch.Height = 50;
DrawingBrush blackBrush = new DrawingBrush();
GeometryDrawing backgroundSquare = new GeometryDrawing(System.Windows.Media.Brushes.White,null,new RectangleGeometry(new Rect(25, 0, 50, 50)));
GeometryGroup gGroup = new GeometryGroup();
gGroup.Children.Add(new RectangleGeometry(new Rect(25, 0, 100, 100)));
GeometryDrawing checkers = new GeometryDrawing(new SolidColorBrush(Colors.Black), null, gGroup);
DrawingGroup checkersDrawingGroup = new DrawingGroup();
checkersDrawingGroup.Children.Add(backgroundSquare);
checkersDrawingGroup.Children.Add(checkers);
blackBrush.Drawing = checkersDrawingGroup;
blackBrush.Viewport = new Rect(0, 0, 0.25, 0.25);
blackBrush.TileMode = TileMode.Tile;
swatch.Fill = blackBrush;
sp_Thumbnails.Children.Add(swatch);
Its simple to have three sections just have one more GeometryDrawing object within your drawingGroup.
you can also configure the number of GeometryDrawing will be there within your drawingGroup as below.
Please see the generic solution to your problem that will display horizontal sections as per the groupCount value.
public void CreateRectangle(int groupCount)
{
Rectangle swatch = new System.Windows.Shapes.Rectangle();
swatch.Width = 50;
swatch.Height = 50;
double groupsize = 100 / groupCount;
DrawingBrush blackBrush = new DrawingBrush();
DrawingGroup checkersDrawingGroup = new DrawingGroup();
//Considering 3 as groupCount
List<SolidColorBrush> brushes = new List<SolidColorBrush>() { Brushes.Black, Brushes.White,Brushes.Red };
double location = 0;
for (int i = 0; i < groupCount; i++)
{
GeometryDrawing drawing = new GeometryDrawing(brushes[i] , null,
new RectangleGeometry(new Rect(0, location,groupsize,groupsize)));
checkersDrawingGroup.Children.Add(drawing);
location += groupsize;
}
blackBrush.Drawing = checkersDrawingGroup;
swatch.Fill = blackBrush;
brdrect.Children.Add(swatch);
}
To fill your rectangle half with black and half with white. I modified your code as below. This will create a rectangle with lines separating two sections vertically.
Rectangle swatch = new System.Windows.Shapes.Rectangle();
swatch.Width = 50;
swatch.Height = 50;
DrawingBrush blackBrush = new DrawingBrush();
GeometryDrawing backgroundSquare = new GeometryDrawing(Brushes.White, null,
new RectangleGeometry(new Rect(0, 0, 25, 25)));
GeometryGroup gGroup = new GeometryGroup();
gGroup.Children.Add(new RectangleGeometry(new Rect(25, 0, 25, 25)));
GeometryDrawing checkers = new GeometryDrawing(Brushes.Black, null, gGroup);
DrawingGroup checkersDrawingGroup = new DrawingGroup();
checkersDrawingGroup.Children.Add(backgroundSquare);
checkersDrawingGroup.Children.Add(checkers);
blackBrush.Drawing = checkersDrawingGroup;
swatch.Fill = blackBrush;
brdrect.Children.Add(swatch);
If you want your sections to be spliced horizontally then you will need few changes in above code.
just modify the rectangle drawing creation section as below.
GeometryDrawing backgroundSquare = new GeometryDrawing(Brushes.White, null,
new RectangleGeometry(new Rect(0, 0, 25, 25)));
GeometryGroup gGroup = new GeometryGroup();
gGroup.Children.Add(new RectangleGeometry(new Rect(0, 25, 25, 25)));
GeometryDrawing checkers = new GeometryDrawing(Brushes.Black, null, gGroup);
This is my Chart control Graph:
I want to remove axis black lines from the left side and add blue line as a frame for all the graph like at the button.
I have search for all the properties and try to change color but the default color still remained
I know this old post but to answer the OP question.
Changes the line color and line style
Chart1.ChartAreas(0).AxisY.LineColor = Color.Blue
Chart1.ChartAreas(0).AxisY.LineDashStyle =ChartDashStyle.Dot
If want to remove the tick marks you use this code
Chart1.ChartAreas(0).AxisY.MajorTickMark.Enabled = False
Chart1.ChartAreas(0).AxisY.MinorTickMark.Enabled = False
if you want to customize a chart you could draw your own dynamically:
Example in VB.net:
Const GraphHeight As Integer = 100
Const GraphWidth As Integer = 200
Dim cIMG As New Bitmap(GraphWidth, GraphHeight)
Dim G As Graphics = Graphics.FromImage(cIMG)
Dim red As Integer = 0
Dim pnts(4) As Point
pnts(0) = New Point(0, GraphHeight - 0)
pnts(1) = New Point(50, GraphHeight - 80)
pnts(2) = New Point(100, GraphHeight - 50)
pnts(3) = New Point(150, GraphHeight - 40)
pnts(4) = New Point(200, GraphHeight - 20)
G.DrawLines(Pens.Blue, pnts)
PictureBox1.Image = cIMG
Example in C#:
const int GraphHeight = 100;
const int GraphWidth = 200;
Bitmap cIMG = new Bitmap(GraphWidth, GraphHeight);
Graphics G = Graphics.FromImage(cIMG);
int red = 0;
Point[] pnts = new Point[5];
pnts(0) = new Point(0, GraphHeight - 0);
pnts(1) = new Point(50, GraphHeight - 80);
pnts(2) = new Point(100, GraphHeight - 50);
pnts(3) = new Point(150, GraphHeight - 40);
pnts(4) = new Point(200, GraphHeight - 20);
G.DrawLines(Pens.Blue, pnts);
PictureBox1.Image = cIMG;
you could use a loop to draw the grid
Example
I need to mask dynamically created images, so that they will be shown as circles.
Pictures can be square, but are usually rectangles... so the circle that will be shown can be taken from the center of it...so the shown circle must be inscribed in the picture and centered in the center of it.
This is the code I'm using right now:
//Setting up the image
Image image = new Image();
image.Height = 70;
image.Width = 70;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("http://url-of-the-image", UriKind.Absolute);
image.CacheMode = new BitmapCache();
image.Source = bitmapImage;
image.Stretch = Stretch.UniformToFill;
image.VerticalAlignment = System.Windows.VerticalAlignment.Center;
//Setting up the mask
RadialGradientBrush opacityMask = new RadialGradientBrush();
GradientStop gs1 = new GradientStop();
GradientStop gs2 = new GradientStop();
GradientStop gs3 = new GradientStop();
gs1.Color = Color.FromArgb(255, 0, 0, 0);
gs1.Offset = 0.0;
gs2.Color = Color.FromArgb(255, 0, 0, 0);
gs2.Offset = 0.999;
gs3.Color = Color.FromArgb(0, 0, 0, 0);
gs3.Offset = 1.0;
opacityMask.GradientStops.Add(gs1);
opacityMask.GradientStops.Add(gs2);
opacityMask.GradientStops.Add(gs3);
image.OpacityMask = opacityMask;
//Showing the image
panel.Children.Add(image);
This all works fine, but when the pictures are rectangular and not square, this creates an ellipse instead of a circle... any idea on how can I force it to create a circle?
I also tried to specify some more parameters, but doesn't seem to help:
opacityMask.Center = new Point(0.5, 0.5);
opacityMask.RadiusX = 0.5;
opacityMask.RadiusY = 0.5;
Okay, today i tried again to fix this, and i came out with a solution.
It's not the best, more clean solution ever...but works :)
I basically wrapped the picture (not masked) into a StackPanel and then applied the mask to the StackPanel instead ;)
This is how it looks like (the only lines that change from the original are the the last few ones):
//Setting up the image
Image image = new Image();
image.Height = 70;
image.Width = 70;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("http://url-of-the-image", UriKind.Absolute);
image.CacheMode = new BitmapCache();
image.Source = bitmapImage;
image.Stretch = Stretch.UniformToFill;
image.VerticalAlignment = System.Windows.VerticalAlignment.Center;
//Setting up the mask
RadialGradientBrush opacityMask = new RadialGradientBrush();
GradientStop gs1 = new GradientStop();
GradientStop gs2 = new GradientStop();
GradientStop gs3 = new GradientStop();
gs1.Color = Color.FromArgb(255, 0, 0, 0);
gs1.Offset = 0.0;
gs2.Color = Color.FromArgb(255, 0, 0, 0);
gs2.Offset = 0.999;
gs3.Color = Color.FromArgb(0, 0, 0, 0);
gs3.Offset = 1.0;
opacityMask.GradientStops.Add(gs1);
opacityMask.GradientStops.Add(gs2);
opacityMask.GradientStops.Add(gs3);
//Setting up the StackPanel
StackPanel sp = new StackPanel();
sp.OpacityMask = opacityMask;
//Showing the image
sp.Children.Add(image);
panel.Children.Add(sp);