<controls:RadialProgressBar Margin="10,0,0,0" x:Name="RadialProgressBarControl"
Value="0"
Minimum="0"
Maximum="180"
Thickness="0"
Outline="#FFD6DCDA"
Foreground="#FF9646E6"
Width="300"
Height="300" FontFamily="Palatino Linotype">
</controls:RadialProgressBar>
<TextBlock Canvas.ZIndex="100" Margin="10,0,0,0" FontFamily="Palatino Linotype" FontSize="55" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FF786DDB" Text="{x:Bind RadialProgressBarControl.Value, Mode=OneWay}">
while (RadialProgressBarControl.Value < 180)
{
RadialProgressBarControl.Value += 1;
RadialProgressBarControl.Thickness += 0.15;
await Task.Delay(5);
}
I have 2 problem
is how can I insert the "%" to the ?
I want my circle "path" change the color while load the value from one to 180
is how can I insert the "%" to the ?
If you want to insert %to your TextBlock, you could create a TextConverter inherit IValueConverter. And use it to format text like the follow.
internal class TextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return string.Format("{0} %", value);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
Usage
<Page.Resources>
<local:TextConverter x:Key="MyConverter" />
</Page.Resources>
<TextBlock Text="{x:Bind RadialProgressBarControl.Value, Mode=OneWay, Converter={StaticResource MyConverter}}"></TextBlock>
I want my circle "path" change the color while load the value from one to 180
You could set the foreground of RadialProgressBarControl in the code behind with SolidColorBrush dynamically.
Color Tem = new Color();
while (RadialProgressBarControl.Value < 180)
{
RadialProgressBarControl.Value += 1;
RadialProgressBarControl.Thickness += 0.15;
Tem.A = 255;
Tem.R += 1;
Tem.B += 1;
Tem.G += 1;
RadialProgressBarControl.Foreground = new SolidColorBrush(Tem);
await Task.Delay(5);
}
Related
I have code as per attached that builds a Xamrin Grid virtually in code. The problem that I have not been able to resolve is Events that will be triggered when entering data into a cell.
Here is the output:
Output 1
Output 2
The purpose of this post is to create an event that can be invoked to take action when data is entered into any of the cells created at runtime in the grid.
<?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="VarGridSample.MainPage">
<ScrollView>
<StackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Label
Text="Variable Grid"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="I am attempting to build a Grid at runtime to allow for variable rows and columns. The Grid has been initially defined in the Content Page. The Grid is built in the code based on the number of rows and columns requested. Entry controls are built for each cell. The problem is how to build the Events for each cell...ANY IDEAS?"
FontSize="18"
HorizontalOptions="Center" />
<Entry x:Name="Rows"
Text="{Binding Rows }"
HorizontalOptions="Center" Placeholder="Enter Total Rows" WidthRequest="150" />
<Entry x:Name="Cols"
Text="{Binding Rows }"
HorizontalOptions="Center" Placeholder="Enter Total Columns" WidthRequest="150" />
<Button x:Name="BuildGrid"
Text="Build Grid" HorizontalOptions="Center" Clicked="BuildGrid_Clicked" />
<Grid x:Name="VarGrid">
</Grid>
</StackLayout>
</ScrollView>
</ContentPage>
Below is the C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace VarGridSample
{
public partial class MainPage : ContentPage
{
private int rows { get; set; }
private int cols { get; set; }
private int cellcntr = 0;
public MainPage()
{
InitializeComponent();
}
private void BuildGrid_Clicked(object sender, EventArgs e)
{
rows = Int32.Parse(Rows.Text);
cols = Int32.Parse(Cols.Text);
for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
VarGrid.RowDefinitions.Add(new RowDefinition());
}
for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
for (int colIndex = 0; colIndex < cols; colIndex++)
{
var entry = new Entry
{
Text = "cell" + (cellcntr).ToString(),
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center
};
VarGrid.Children.Add(entry, colIndex, rowIndex);
cellcntr++;
}
}
}
}
}
You can add this to MainPage.xaml.cs:
private void BuildGrid_Clicked(object sender, EventArgs e)
{
rows = Int32.Parse(Rows.Text);
cols = Int32.Parse(Cols.Text);
for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
VarGrid.RowDefinitions.Add(new RowDefinition());
}
for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
for (int colIndex = 0; colIndex < cols; colIndex++)
{
var entry = new Entry
{
Text = "cell" + (cellcntr).ToString(),
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
};
//add the event
entry.TextChanged += Entry_TextChanged;
VarGrid.Children.Add(entry, colIndex, rowIndex);
cellcntr++;
}
}
}
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
{
Console.WriteLine(e.OldTextValue);
var entry = (Entry)sender;
var parent= (Grid)entry.Parent;
Console.WriteLine(parent.Children.Count);
}
I'm using Xamarin.Forms.Datagrid. What I'm struggling with is displaying the second row. I suspect it is in the adding value part that I'm not specifying to add a new row to the Datagrid. But for the life of me I can't see it.
Now if I scanned a different barcode. It adds the new value to the collection but does not expand the datagrid.
My ObservableCollection:
public ObservableCollection<dgvProductionReceiptSource> ProductionReceiptSource { get; } = new ObservableCollection<dgvProductionReceiptSource>();
Where I get my data from:
private void FillDataGrid()
{
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("SELECT DocNum, OWOR.ItemCode, ItemName, PlannedQty, CAST(OWOR.DueDate AS DATE) FROM OWOR " +
"INNER JOIN OITM ON OWOR.ItemCode = OITM.ItemCode WHERE Status = 'R' AND OWOR.DocNum = '" + ScanBarcodeText + "' ORDER BY DueDate ASC", connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader != null)
{
while (reader.Read())
{
ItemNum = reader.GetString(1);
Desc = reader.GetString(2);
PlannedQty = reader.GetDecimal(3);
DueDate = reader.GetDateTime(4);
ScanQty = 0;
if (DueDate == DateTime.Today)
{
if (DocNum.ToString() == ScanBarcodeText)
{
AddQty();
}
if (DocNum.ToString() != ScanBarcodeText)
{
DocNum = reader.GetInt32(0);
ProductionReceiptSource.Add(new dgvProductionReceiptSource()
{
DocNumProductionReceipt = DocNum,
ItemNumberProductionReceipt = reader.GetString(1),
DescriptionProductionReceipt = reader.GetString(2),
PlannedQuantityProductionReceipt = reader.GetDecimal(3),
ScannedQuantityProductionReceipt = 0
});
AddQty();
}
}
}
}
}
}
connection.Close();
}
ScanBarcodeText = string.Empty;
}
catch(Exception ex)
{
Application.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
}
}
Any help would be appreciated
Like Jason suggested, I need to increase the height of the control
<ContentView HeightRequest="380">
<ScrollView Orientation="Horizontal">
<dg:DataGrid x:Name="dgvProductionReceiptSource"
ItemsSource="{Binding ProductionReceiptSource}"
IsRefreshing="{Binding ProductionReceiptRefresh}"
PullToRefreshCommand="{Binding ProductionReceiptRefreshCommand}"
IsVisible="False"
RowHeight="60"
HeaderHeight="50"
HeaderBackground="#e0e6f8"
HeaderFontSize="15"
ActiveRowColor="#8899AA">
<x:Arguments>
<ListViewCachingStrategy>RetainElement</ListViewCachingStrategy>
</x:Arguments>
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="Order Number" PropertyName="DocNumProductionReceipt" Width="150"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<dg:DataGridColumn Title="Item Number" PropertyName="ItemNumberProductionReceipt" Width="150"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<dg:DataGridColumn Title="Item Description" PropertyName="DescriptionProductionReceipt" Width="150"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<dg:DataGridColumn Title="Planned Quantity" PropertyName="PlannedQuantityProductionReceipt" Width="150"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<dg:DataGridColumn Title="Scanned Bin" PropertyName="ScannedBinsProductionReceipt" Width="150"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<dg:DataGridColumn Title="Remaining Bins" PropertyName="RemainingBinsProductionReceipt" Width="150"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</dg:DataGrid.Columns>
<dg:DataGrid.RowsBackgroundColorPalette>
<dg:PaletteCollection>
<Color>#E0E6f8</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsBackgroundColorPalette>
</dg:DataGrid>
</ScrollView>
</ContentView>
I changed the ContentView HeightRequest
WrapGrid in ItemsControl takes the width of the first item as the default width of all children items. Is there any workaround to make the itemwidth stretch according to each individual item's content?
Here's My XAML.
<Grid Grid.Row="2">
<ItemsControl Grid.Column="1" ItemsSource="{x:Bind articleTags}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="#E1E1E1" HorizontalAlignment="Stretch" Background="#E1E1E1" Margin="4,4,0,0">
<TextBlock Text="{Binding NAME}" Margin="6,0,6,0"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Screenshots:
In the second image the 'newsletters' item is not being fully displayed as it takes the width of the first item.
How to solve this?
Change the WrapGrid to ItemsStackPanel
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
UPDATE
Try to use custom wrap grid panel according to this sample
public class CustomWrapPanel : Panel
{
protected override Size MeasureOverride(Size availableSize)
{
// Just take up all of the width
Size finalSize = new Size { Width = availableSize.Width };
double x = 0;
double rowHeight = 0d;
foreach (var child in Children)
{
// Tell the child control to determine the size needed
child.Measure(availableSize);
x += child.DesiredSize.Width;
if (x > availableSize.Width)
{
// this item will start the next row
x = child.DesiredSize.Width;
// adjust the height of the panel
finalSize.Height += rowHeight;
rowHeight = child.DesiredSize.Height;
}
else
{
// Get the tallest item
rowHeight = Math.Max(child.DesiredSize.Height, rowHeight);
}
}
// Add the final height
finalSize.Height += rowHeight;
return finalSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
Rect finalRect = new Rect(0, 0, finalSize.Width, finalSize.Height);
double rowHeight = 0;
foreach (var child in Children)
{
if ((child.DesiredSize.Width + finalRect.X) > finalSize.Width)
{
// next row!
finalRect.X = 0;
finalRect.Y += rowHeight;
rowHeight = 0;
}
// Place the item
child.Arrange(new Rect(finalRect.X, finalRect.Y, child.DesiredSize.Width, child.DesiredSize.Height));
// adjust the location for the next items
finalRect.X += child.DesiredSize.Width;
rowHeight = Math.Max(child.DesiredSize.Height, rowHeight);
}
return finalSize;
}
}
How I can attach DragStarted DragDelta events to a grid in windows 8 / WinRT. I did the Same in windows phone with GestureService.GetGestureListener() method. I tried to replace the code with ManipulationStarted & ManipulationDelta events in windows 8. But the result is not same. In windows phone for a single drag it enters DragDelta events 2 or more times. But in the other hand in windows 8, in ManupulationDelta event it only fires once for the similar Drag operation.
Yeah, I think I know what you want.
Let's say you have some XAML like this:
<Grid Margin="50">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Rectangle Fill="Blue" x:Name="MyRect" />
</Grid>
You want to move that rectangle around the Grid by dragging it.
Just use this code:
public MainPage()
{
this.InitializeComponent();
MyRect.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
MyRect.ManipulationDelta += Rectangle_ManipulationDelta;
MyRect.ManipulationCompleted += Rectangle_ManipulationCompleted;
}
private void Rectangle_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var _Rectangle = sender as Windows.UI.Xaml.Shapes.Rectangle;
var _Transform = (_Rectangle.RenderTransform = (_Rectangle.RenderTransform as TranslateTransform) ?? new TranslateTransform()) as TranslateTransform;
_Transform.X += e.Delta.Translation.X;
_Transform.Y += e.Delta.Translation.Y;
}
private void Rectangle_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
var _Rectangle = sender as Windows.UI.Xaml.Shapes.Rectangle;
_Rectangle.RenderTransform = null;
var _Column = System.Convert.ToInt16(_Rectangle.GetValue(Grid.ColumnProperty));
if (_Column <= 0 && e.Cumulative.Translation.X > _Rectangle.RenderSize.Width * .5)
_Rectangle.SetValue(Grid.ColumnProperty, 1);
else if (_Column == 1 && e.Cumulative.Translation.X < _Rectangle.RenderSize.Width * -.5)
_Rectangle.SetValue(Grid.ColumnProperty, 0);
var _Row = System.Convert.ToInt16(_Rectangle.GetValue(Grid.RowProperty));
if (_Row <= 0 && e.Cumulative.Translation.Y > _Rectangle.RenderSize.Height * .5)
_Rectangle.SetValue(Grid.RowProperty, 1);
else if (_Row == 1 && e.Cumulative.Translation.Y < _Rectangle.RenderSize.Height * -.5)
_Rectangle.SetValue(Grid.RowProperty, 0);
}
For this:
Hope I'm close!
Best of luck!
I am writing a Silverlight 4 business application and have run into an issue. I need the text input in TextBoxes to be forced to UpperCase. What I understand from various forums is Silverlight does not Implement CharacterCasing and CSS Styling.
Is there any other way to achieve this?
You can achieve this by creating a behavior, like this:
public class UpperCaseAction : TriggerAction<TextBox>
{
protected override void Invoke(object parameter)
{
var selectionStart = AssociatedObject.SelectionStart;
var selectionLenght = AssociatedObject.SelectionLength;
AssociatedObject.Text = AssociatedObject.Text.ToUpper();
AssociatedObject.SelectionStart = selectionStart;
AssociatedObject.SelectionLength = selectionLenght;
}
}
Then, use it in your TextBox, like this:
<Grid x:Name="LayoutRoot" Background="White">
<TextBox TextWrapping="Wrap" VerticalAlignment="Top" Margin="10">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<ASD_Answer009_Behaviors:UpperCaseAction/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
</Grid>
Where i: is a namespace for
clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity
Code behind:
System.Windows.Interactivity.EventTrigger eventTrigger = new System.Windows.Interactivity.EventTrigger("TextChanged");
eventTrigger.Actions.Add(new UpperCaseAction());
System.Windows.Interactivity.Interaction.GetTriggers(myTextBox).Add(eventTrigger);
In order to create and use behaviors, you need to download and install the Expression Blend SDK for Silverlight 4 and add a reference to System.Windows.Interactivity.dll.
Try this:
private void txt2_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = MakeUpperCase((TextBox)sender, e);
}
bool MakeUpperCase(TextBox txt, KeyEventArgs e)
{
if (Keyboard.Modifiers != ModifierKeys.None || (e.Key < Key.A) || (e.Key > Key.Z)) //do not handle ModifierKeys (work for shift key)
{
return false;
}
else
{
string n = new string(new char[] { (char)e.PlatformKeyCode });
int nSelStart = txt.SelectionStart;
txt.Text = txt.Text.Remove(nSelStart, txt.SelectionLength); //remove character from the start to end selection
txt.Text = txt.Text.Insert(nSelStart, n); //insert value n
txt.Select(nSelStart + 1, 0); //for cursortext
return true; //stop to write in txt2
}
}
private void txt2_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers != ModifierKeys.None) return; //do not handle ModifierKeys (work for shift key)
string n = new string(new char[] { (char)e.PlatformKeyCode });
int nSelStart = txt2.SelectionStart;
txt2.Text = txt2.Text.Remove(nSelStart, txt2.SelectionLength); //remove character from the start to end selection
txt2.Text = txt2.Text.Insert(nSelStart, n); //insert value n
txt2.Select(nSelStart + 1, 0); //for cursortext
e.Handled = true; //stop to write in txt2
}