I know i can use < para /> to create multiline function comments
/// <summary>
/// updates the car scrolling.<para />
/// there are also colors
/// <para />while clearall will remove all </summary>
/// <param name="status">optional to add a new car </param>
public void UpdateDrawing(int updatestatus = bgcar.color.none)
but that behaviour isnt like a linebreak \n it rather behaves like a double line brake ( \n\n ). Is there a way to have only a single line break.
So textblocks could be created for intellisence
Try this:
/// <summary>
/// <para>updates the car scrolling.</para>
/// <para>there are also colors</para>
/// <para>while clearall will remove all</para>
/// </summary>
Related
How to create a DataTemplate with code?
DataTemplate does not have a VisualTree property like in WPF.
The docu doesn't help either.
There is an IDataTemplateController, but it does not control anything. <ignorable>weird MAUI times again</ignorable>.
Found it in source code: There is a constructor parameter for a function which creates the view.
/// <Docs>
/// <param name="loadTemplate">A custom content generator to be called </param>
/// <summary>Creates and initializes a new instance of the <see cref="T:Microsoft.Maui.Controls.DataTemplate" /> class.</summary>
/// <remarks>To be added.</remarks>
/// </Docs>
public DataTemplate(Func<object> loadTemplate);
new DataTemplate(() => {
var label = new Label();
label.SetBinding(Label.TextProperty, new Binding("."));
return label;
});
There is currently a bug in Binding and you have to specify ".", a fix is merged.
I have a message extension for MS Teams (based on Bot Framework v3). When I create a ThumbnailCard and return it to user, Teams inserts name and logo of my app to card. Can I remove them somehow?
This is how I create a card
var card = new ThumbnailCard { Text = "some text", Title= "title"};
Here is a screenshot:
No, the attribution on cards created by a messaging extension can't be removed by the app. Teams will automatically show it.
The ThumbnailCard object has the constructor:
/// <summary>
/// Initializes a new instance of the ThumbnailCard class.
/// </summary>
/// <param name="title">Title of the card</param>
/// <param name="subtitle">Subtitle of the card</param>
/// <param name="text">Text for the card</param>
/// <param name="images">Array of images for the card</param>
/// <param name="buttons">Set of actions applicable to the current
/// card</param>
/// <param name="tap">This action will be activated when user taps on
/// the card itself</param>
public ThumbnailCard(string title = default(string), string subtitle = default(string), string text = default(string), IList<CardImage> images = default(IList<CardImage>), IList<CardAction> buttons = default(IList<CardAction>), CardAction tap = default(CardAction))
{
Title = title;
Subtitle = subtitle;
Text = text;
Images = images;
Buttons = buttons;
Tap = tap;
CustomInit();
}
Have you tried with images = new List<CardImage>() ? same thing for buttons
I have a WPF xaml template and associated code behind with a variety of controls. The user can move these controls around so that one has the layout that one desires. However, once the user restarts the program, the controls return to their original locations. How do I make it so that the user can save the layout?
You can save, reload the layout (xaml):
After the user changes the layout [on Window Closing event], You can save a XAML file base changed layout using XamlWriter static class. In fact you serialize the container control and save it in a file.
Also you need some codes [in the window constructor after InitializeComponent()] to reload serialized layout of the container control [and its controls] from the file.
I put a sample (wrote by Matt Searles), here:
<StackPanel>
<WrapPanel x:Name="wrapPanel1" Height="200"></WrapPanel>
<Button Click="AddButton">Add Button</Button>
<Button Click="SaveButtons">Save Buttons</Button>
<Button Click="ReloadButtons">Reload Buttons</Button>
</StackPanel>
Code behind:
/// <summary>
/// Add a button to wrapPanel1
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddButton(object sender, RoutedEventArgs e)
{
// Create the Button.
Button button = new Button();
button.Height = 50;
button.Width = 100;
button.Background = Brushes.AliceBlue;
button.Content = "Click Me";
wrapPanel1.Children.Add(button);
}
/// <summary>
/// Save wrapPanel1 to AA.xaml
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveButtons(object sender, RoutedEventArgs e)
{
StringBuilder outstr = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
XamlDesignerSerializationManager dsm = new XamlDesignerSerializationManager(XmlWriter.Create(outstr, settings));
dsm.XamlWriterMode = XamlWriterMode.Expression;
XamlWriter.Save(wrapPanel1, dsm);
string savedControls = outstr.ToString();
File.WriteAllText(#"AA.xaml", savedControls);
}
/// <summary>
/// Reload the buttons in AA.xaml
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ReloadButtons(object sender, RoutedEventArgs e)
{
StreamReader sR = new StreamReader(#"AA.xaml");
string text = sR.ReadToEnd();
sR.Close();
StringReader stringReader = new StringReader(text);
XmlReader xmlReader = XmlReader.Create(stringReader);
WrapPanel wp = (WrapPanel)System.Windows.Markup.XamlReader.Load(xmlReader);
wrapPanel1.Children.Clear(); // clear the existing children
foreach (FrameworkElement child in wp.Children) // and for each child in the WrapPanel we just loaded (wp)
{
wrapPanel1.Children.Add(CloneFrameworkElement(child)); // clone the child and add it to our existing wrap panel
}
}
/// <summary>
/// Clone a framework element by serializing and deserializing it
/// </summary>
/// <param name="originalElement"></param>
/// <returns></returns>
FrameworkElement CloneFrameworkElement(FrameworkElement originalElement)
{
string elementString = XamlWriter.Save(originalElement);
StringReader stringReader = new StringReader(elementString);
XmlReader xmlReader = XmlReader.Create(stringReader);
FrameworkElement clonedElement = (FrameworkElement)XamlReader.Load(xmlReader);
return clonedElement;
}
I have a UIPopoverController that I am using and I have two buttons each displays a popup when clicked. However, I do not want the popup to be displayed at the same time - meaning I do not want the user to be able to press the one button and while the popup is displayed be able to press the other button. It seems like I have tried everything - disabling the user interaction on the buttons, hiding the view behind the pop up, using passthrough views for the pop and more. None of it works! The disabling of the user interaction seems to work for the most part but then stops disallowing the user to interact with the button and causes the application to crash...
popupView.PassthroughViews = new UIView[]{this.View.Superview, this.View, this.Gray}; //gray is another view that sits under the view that calls the popup
this.View.UserInteractionEnabled = false;
this.PositiveMeterBtn.UserInteractionEnabled = false;
this.View.Hidden = true;
My UIPopoverController is declared at the class level and I have even done code like this:
if(popupView != null)
return;
I still get multiple popups. I am using mono touch/xamarin - is this a bug with xamarin or an ios issue? Am I handling this in the correct manner?
I haven't worked with Xamarin before, but what's worked for me in native Objective-C is
[controller setModalInPopover:YES];
where controller is the view controller displayed within the popover.
From the UIViewController class reference:
#property(nonatomic, readwrite, getter=isModalInPopover) BOOL modalInPopover
The default value of this property is NO. Setting it to YES causes an owning popover controller to disallow interactions outside this view controller while it is displayed.
You can either make the popover modal but if it doesn't contain content that is meant to be modal, you shouldn't block the user.
Usually the better option is to make two helper methods and place them for instance in your app delegate. The methods take care that an existing popover is dismissed if another one is to be shown. This way you will have a maximum of on UIPopoverController and don't have to worry about dismissal.
/// <summary>
/// Shows a popover.
/// </summary>
/// <param name='controllerToShow'>the controller to show in the popover</param>
/// <param name='showFromRect'>the rectangle to present the popover from. Not used if showFromItem is specified.</param>
/// <param name='showInView'>the view the popover is hosted in</param>
/// <param name='showFromItem'>the bar button item the popover gets presented from.</param>
/// <param name='popoverContentSize'>the content size of the popover</param>
/// <param name='animated'>If set to <c>true</c>, animated the popover</param>
/// <param name='arrowDirection'>the allowed arrow directions</param>
/// <param name='onDismiss'>callback if the popover gets dismissed. Careful that the object that owns the callback doesn't outlive the popover controller to prevent uncollectable memory.</param>
public static void ShowPopover(UIViewController controllerToShow, RectangleF showFromRect, UIView showInView, UIBarButtonItem showFromItem, SizeF popoverContentSize, bool animated = true, UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirection.Any, EventHandler onDismiss = null)
{
if(AppDelegateBase.popoverController != null)
{
AppDelegateBase.DismissPopover(false);
}
if(showFromItem == null && showFromRect.IsEmpty)
{
// Nothing to attach the popover to.
return;
}
popoverController = new UIPopoverController(controllerToShow);
if(!popoverContentSize.IsEmpty)
{
popoverController.SetPopoverContentSize(popoverContentSize, false);
}
if(onDismiss != null)
{
popoverController.DidDismiss += onDismiss;
}
// Send a notification that a popover will be presented.
NSNotificationCenter.DefaultCenter.PostNotificationName("WillPresentPopover", popoverController);
if(showFromItem != null)
{
popoverController.PresentFromBarButtonItem(showFromItem, arrowDirection, animated);
}
else
{
popoverController.PresentFromRect(showFromRect, showInView, arrowDirection, animated );
}
}
/// <summary>
/// Dismisses the popover presented using ShowPopover().
/// </summary>
/// <param name='animated'>If set to <c>true</c>, animates the dismissal</param>
public static void DismissPopover(bool animated = false)
{
if(popoverController != null)
{
popoverController.Dismiss(animated);
}
AppDelegateBase.popoverController = null;
}
private static UIPopoverController popoverController;
One thing you might try is using the method
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
And in that method check if one of your popover view controller's is on screen.
if (popupView.view.window) {
return NO;
} else {
return YES;
}
I have a problem with databinding in a winforms-application.
In the following code i have a databinding to the enabled-property of a textbox. The enabled-state depends on the value of a checkbox.
tbAmount.DataBindings.Add("Enabled", checkBox, "Checked",
false, DataSourceUpdateMode.OnPropertyChanged);
in this code the textbox is enabled if the checkbox is checked. but i need it inverted. i want the textbox to be enabled if the checkbox is unchecked. How can i achieve this?
This should do it.
Binding bind = new Binding("Enabled", checkBox, "Checked");
bind.Format +=
(sender, e) =>
e.Value = !((bool)e.Value); // invert the checked value
textBox.DataBindings.Add(bind);
I know this is a very old post, but I have looked for something similar many times over the years and was never really happy with what I ended up using. Mike Park's answer is great, not only because it works, but because of how simple it is.
All I did was take Mike's answer and turn it into a Control extension. Thanks Mike!
Depending on where and how you use it, you may need to add a reference to System.Windows.Forms and a using System.Windows.Forms statement.
/// <summary>
/// Creates a DataBinding that allows you to bind to the Unchecked state instead of the normal Checked state.
///
/// Sample usage: In this case, I am enabling a Button when the CheckBox is unchecked.
/// // Defaults to Control Enabled property.
/// // Always bound to the DataSource Checked property.
/// YourButton.DataBindings.Add(YourButton.UncheckedBinding(YourCheckBox));
///
/// var binding = YourButton.UncheckedBinding(YourCheckBox);
/// YourButton.DataBindings.Add(binding);
///
/// Adapted - from answer by Mike Park answered Oct 18 '12 at 19:11
/// From: Databinding Enabled if false
/// Link: https://stackoverflow.com/questions/12961533/databinding-enabled-if-false
/// </summary>
/// <typeparam name="T">Constrained to be a type that inherits from ButtonBase. This includes CheckBoxes and RadionButtons.</typeparam>
/// <param name="control">The control that will consume the DataBinding.</param>
/// <param name="DataSource">The control to which we are binding. We will always bind to the Checked property.</param>
/// <returns>DataBinding that is bound to the Unchecked state instead of the usual Checked state.</returns>
public static Binding UncheckedBinding<T>(this Control control, T DataSource) where T : ButtonBase
{
return UncheckedBinding(control, "Enabled", DataSource);
}
/// <summary>
/// Creates a DataBinding that allows you to bind to the Unchecked state instead of the normal Checked state.
///
/// Sample usage: In this case, I am enabling a Button when the CheckBox is unchecked.
/// // Always bound to the DataSource Checked property.
/// YourButton.DataBindings.Add(YourButton.UncheckedBinding("Enabled", YourCheckBox));
///
/// var binding = YourButton.UncheckedBinding(YourCheckBox);
/// YourButton.DataBindings.Add(binding);
///
/// Adapted - from answer by Mike Park answered Oct 18 '12 at 19:11
/// From: Databinding Enabled if false
/// Link: https://stackoverflow.com/questions/12961533/databinding-enabled-if-false
/// </summary>
/// <typeparam name="T">Constrained to be a type that inherits from ButtonBase. This includes CheckBoxes and RadionButtons.</typeparam>
/// <param name="control">The control that will consume the DataBinding.</param>
/// <param name="DataSource">The control to which we are binding. We will always bind to the Checked property.</param>
/// <param name="PropertyName">The name of the property that is being bound.</param>
/// <returns>DataBinding that is bound to the Unchecked state instead of the usual Checked state.</returns>
public static Binding UncheckedBinding<T>(this Control control, string PropertyName, T DataSource) where T : ButtonBase
{
var binding = new Binding(PropertyName, DataSource, "Checked");
binding.Format += (sender, e) => e.Value = !((bool)e.Value);
return binding;
}