本文整理汇总了C#中Windows.UI.Xaml.Controls.Border.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Border.SetBinding方法的具体用法?C# Border.SetBinding怎么用?C# Border.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Controls.Border
的用法示例。
在下文中一共展示了Border.SetBinding方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPathChanged
private static void OnPathChanged( DependencyObject obj, DependencyPropertyChangedEventArgs args )
{
var icon = (Icon) obj;
var data = (string) args.NewValue;
if ( data == null )
{
return;
}
// Copy it since sharing it isn't permitted
var path = (Path) XamlReader.Load( "<Path xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Data=\"" + data + "\" />" );
path.Stretch = Stretch.Uniform;
path.HorizontalAlignment = HorizontalAlignment.Center;
path.VerticalAlignment = VerticalAlignment.Center;
path.SetBinding( Path.FillProperty, new Binding { Source = icon, Path = new PropertyPath( "Foreground" ) } );
path.SetBinding( Path.MarginProperty, new Binding { Source = icon, Path = new PropertyPath( "Padding" ) } );
var container = new Border
{
Child = path
};
container.SetBinding( Border.WidthProperty, new Binding { Source = icon, Path = new PropertyPath( "IconWidth" ) } );
container.SetBinding( Border.HeightProperty, new Binding { Source = icon, Path = new PropertyPath( "IconHeight" ) } );
container.SetBinding( Border.BackgroundProperty, new Binding { Source = icon, Path = new PropertyPath( "Background" ) } );
icon.HorizontalAlignment = HorizontalAlignment.Center;
icon.VerticalAlignment = VerticalAlignment.Center;
icon.Content = new Viewbox
{
Child = container
};
}
示例2: ExtractButton_Tapped
/// <summary>
/// This is event handler for 'Extract' button.
/// Captures image from camera ,recognizes text and displays it.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void ExtractButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
//Get information about the preview.
var previewProperties = mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
int videoFrameWidth = (int)previewProperties.Width;
int videoFrameHeight = (int)previewProperties.Height;
// In portrait modes, the width and height must be swapped for the VideoFrame to have the correct aspect ratio and avoid letterboxing / black bars.
if (!externalCamera && (displayInformation.CurrentOrientation == DisplayOrientations.Portrait || displayInformation.CurrentOrientation == DisplayOrientations.PortraitFlipped))
{
videoFrameWidth = (int)previewProperties.Height;
videoFrameHeight = (int)previewProperties.Width;
}
// Create the video frame to request a SoftwareBitmap preview frame.
var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, videoFrameWidth, videoFrameHeight);
// Capture the preview frame.
using (var currentFrame = await mediaCapture.GetPreviewFrameAsync(videoFrame))
{
// Collect the resulting frame.
SoftwareBitmap bitmap = currentFrame.SoftwareBitmap;
OcrEngine ocrEngine = OcrEngine.TryCreateFromLanguage(ocrLanguage);
if (ocrEngine == null)
{
rootPage.NotifyUser(ocrLanguage.DisplayName + " is not supported.", NotifyType.ErrorMessage);
return;
}
var imgSource = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
bitmap.CopyToBuffer(imgSource.PixelBuffer);
PreviewImage.Source = imgSource;
var ocrResult = await ocrEngine.RecognizeAsync(bitmap);
// Used for text overlay.
// Prepare scale transform for words since image is not displayed in original format.
var scaleTrasform = new ScaleTransform
{
CenterX = 0,
CenterY = 0,
ScaleX = PreviewControl.ActualWidth / bitmap.PixelWidth,
ScaleY = PreviewControl.ActualHeight / bitmap.PixelHeight
};
if (ocrResult.TextAngle != null)
{
// If text is detected under some angle in this sample scenario we want to
// overlay word boxes over original image, so we rotate overlay boxes.
TextOverlay.RenderTransform = new RotateTransform
{
Angle = (double)ocrResult.TextAngle,
CenterX = PreviewImage.ActualWidth / 2,
CenterY = PreviewImage.ActualHeight / 2
};
}
// Iterate over recognized lines of text.
foreach (var line in ocrResult.Lines)
{
// Iterate over words in line.
foreach (var word in line.Words)
{
// Define the TextBlock.
var wordTextBlock = new TextBlock()
{
Text = word.Text,
Style = (Style)this.Resources["ExtractedWordTextStyle"]
};
WordOverlay wordBoxOverlay = new WordOverlay(word);
// Keep references to word boxes.
wordBoxes.Add(wordBoxOverlay);
// Define position, background, etc.
var overlay = new Border()
{
Child = wordTextBlock,
Style = (Style)this.Resources["HighlightedWordBoxHorizontalLine"]
};
// Bind word boxes to UI.
overlay.SetBinding(Border.MarginProperty, wordBoxOverlay.CreateWordPositionBinding());
overlay.SetBinding(Border.WidthProperty, wordBoxOverlay.CreateWordWidthBinding());
overlay.SetBinding(Border.HeightProperty, wordBoxOverlay.CreateWordHeightBinding());
// Put the filled textblock in the results grid.
TextOverlay.Children.Add(overlay);
}
}
//.........这里部分代码省略.........
示例3: ExtractButton_Tapped
/// <summary>
/// This is event handler for 'Extract' button.
/// Recognizes text from image and displays it.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void ExtractButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
ClearResults();
// Check if OcrEngine supports image resoulution.
if (bitmap.PixelWidth > OcrEngine.MaxImageDimension || bitmap.PixelHeight > OcrEngine.MaxImageDimension)
{
rootPage.NotifyUser(
String.Format("Bitmap dimensions ({0}x{1}) are too big for OCR.", bitmap.PixelWidth, bitmap.PixelHeight) +
"Max image dimension is " + OcrEngine.MaxImageDimension + ".",
NotifyType.ErrorMessage);
return;
}
OcrEngine ocrEngine = null;
if (UserLanguageToggle.IsOn)
{
// Try to create OcrEngine for first supported language from UserProfile.GlobalizationPreferences.Languages list.
// If none of the languages are available on device, method returns null.
ocrEngine = OcrEngine.TryCreateFromUserProfileLanguages();
}
else
{
// Try to create OcrEngine for specified language.
// If language is not supported on device, method returns null.
ocrEngine = OcrEngine.TryCreateFromLanguage(LanguageList.SelectedValue as Language);
}
if (ocrEngine != null)
{
// Recognize text from image.
var ocrResult = await ocrEngine.RecognizeAsync(bitmap);
// Display recognized text.
ExtractedTextBox.Text = ocrResult.Text;
if (ocrResult.TextAngle != null)
{
// If text is detected under some angle in this sample scenario we want to
// overlay word boxes over original image, so we rotate overlay boxes.
TextOverlay.RenderTransform = new RotateTransform
{
Angle = (double)ocrResult.TextAngle,
CenterX = PreviewImage.ActualWidth / 2,
CenterY = PreviewImage.ActualHeight / 2
};
}
// Create overlay boxes over recognized words.
foreach (var line in ocrResult.Lines)
{
Rect lineRect = Rect.Empty;
foreach (var word in line.Words)
{
lineRect.Union(word.BoundingRect);
}
// Determine if line is horizontal or vertical.
// Vertical lines are supported only in Chinese Traditional and Japanese languages.
bool isVerticalLine = lineRect.Height > lineRect.Width;
foreach (var word in line.Words)
{
WordOverlay wordBoxOverlay = new WordOverlay(word);
// Keep references to word boxes.
wordBoxes.Add(wordBoxOverlay);
// Define overlay style.
var overlay = new Border()
{
Style = isVerticalLine ?
(Style)this.Resources["HighlightedWordBoxVerticalLine"] :
(Style)this.Resources["HighlightedWordBoxHorizontalLine"]
};
// Bind word boxes to UI.
overlay.SetBinding(Border.MarginProperty, wordBoxOverlay.CreateWordPositionBinding());
overlay.SetBinding(Border.WidthProperty, wordBoxOverlay.CreateWordWidthBinding());
overlay.SetBinding(Border.HeightProperty, wordBoxOverlay.CreateWordHeightBinding());
// Put the filled textblock in the results grid.
TextOverlay.Children.Add(overlay);
}
}
// Rescale word boxes to match current UI size.
UpdateWordBoxTransform();
rootPage.NotifyUser(
"Image is OCRed for " + ocrEngine.RecognizerLanguage.DisplayName + " language.",
NotifyType.StatusMessage);
//.........这里部分代码省略.........
示例4: ExtractButton_Tapped
//.........这里部分代码省略.........
{
// Recognize text from image.
var ocrResult = await ocrEngine.RecognizeAsync(bitmap);
// Display recognized text.
ExtractedTextBox.Text = ocrResult.Text;
string[] ocrSplit = ocrResult.Text.Split(' ');
long citatioNumber=-1;
foreach(string s in ocrSplit)
{
try
{
long l = long.Parse(s);
if(l>10000)
{
citatioNumber = l;
}
}
catch
{
}
}
if (!emailBox.Text.Equals("") && emailBox.Text.Contains("@"))
{
EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient(emailBox.Text));
email.Subject = "Citation information from Saint Louis Court System app";
email.Attachments.Add(new EmailAttachment(file.Name, file));
string citation = "";
if(citatioNumber==-1)
{
citation = "was not picked up by our OCR. Please look at the image closely to find it. For information on court dates and/or to pay online, visit https://www.courts.mo.gov/casenet/base/welcome.do.";
}
else
{
citation = " is " + citatioNumber + ". You will want to double check this with the image. For information on court dates and/or to pay online, visit https://www.courts.mo.gov/casenet/base/welcome.do.";
}
email.Body = ("Thank you for using the Saint Louis Court System Citation app.\n\n We have attached an image of your citation for future reference."+
" Also included is an attempt to digitize its text. Your citation number "+citation+" The rest of the digitized text is below. \n\n OCR:\n"+ocrResult.Text);
await EmailManager.ShowComposeNewEmailAsync(email);
}
if (ocrResult.TextAngle != null)
{
// If text is detected under some angle in this sample scenario we want to
// overlay word boxes over original image, so we rotate overlay boxes.
TextOverlay.RenderTransform = new RotateTransform
{
Angle = (double)ocrResult.TextAngle,
CenterX = PreviewImage.ActualWidth / 2,
CenterY = PreviewImage.ActualHeight / 2
};
}
// Create overlay boxes over recognized words.
foreach (var line in ocrResult.Lines)
{
Rect lineRect = Rect.Empty;
foreach (var word in line.Words)
{
lineRect.Union(word.BoundingRect);
}
// Determine if line is horizontal or vertical.
// Vertical lines are supported only in Chinese Traditional and Japanese languages.
bool isVerticalLine = lineRect.Height > lineRect.Width;
foreach (var word in line.Words)
{
WordOverlay wordBoxOverlay = new WordOverlay(word);
// Keep references to word boxes.
wordBoxes.Add(wordBoxOverlay);
// Define overlay style.
var overlay = new Border()
{
Style = isVerticalLine ?
(Style)this.Resources["HighlightedWordBoxVerticalLine"] :
(Style)this.Resources["HighlightedWordBoxHorizontalLine"]
};
// Bind word boxes to UI.
overlay.SetBinding(Border.MarginProperty, wordBoxOverlay.CreateWordPositionBinding());
overlay.SetBinding(Border.WidthProperty, wordBoxOverlay.CreateWordWidthBinding());
overlay.SetBinding(Border.HeightProperty, wordBoxOverlay.CreateWordHeightBinding());
// Put the filled textblock in the results grid.
TextOverlay.Children.Add(overlay);
}
}
// Rescale word boxes to match current UI size.
UpdateWordBoxTransform();
}
else
{
}
}
示例5: SetShapeType
private void SetShapeType(ShapeType shapeType)
{
if (_container != null)
{
if (shapeType == ShapeType.Border)
{
var border = new Border();
border.SetBinding(Border.BackgroundProperty, new Binding { Source = this, Path = new PropertyPath("Fill") });
border.SetBinding(Border.BorderBrushProperty, new Binding { Source = this, Path = new PropertyPath("BorderBrush") });
border.SetBinding(Border.BorderThicknessProperty, new Binding { Source = this, Path = new PropertyPath("BorderThickness") });
border.SetBinding(Border.CornerRadiusProperty, new Binding { Source = this, Path = new PropertyPath("CornerRadius") });
_container.Child = border;
}
else
{
Shape shape;
switch (shapeType)
{
case ShapeType.Ellipse:
shape = new Ellipse();
break;
case ShapeType.Rectangle:
default:
shape = new Rectangle();
shape.SetBinding(Rectangle.RadiusXProperty, new Binding { Source = this, Path = new PropertyPath("RadiusX") });
shape.SetBinding(Rectangle.RadiusYProperty, new Binding { Source = this, Path = new PropertyPath("RadiusY") });
break;
}
shape.SetBinding(Shape.FillProperty, new Binding { Source = this, Path = new PropertyPath("Fill") });
shape.SetBinding(Shape.StrokeProperty, new Binding { Source = this, Path = new PropertyPath("Stroke") });
shape.SetBinding(Shape.StrokeThicknessProperty, new Binding { Source = this, Path = new PropertyPath("StrokeThickness") });
_container.Child = shape;
}
}
}