Does anyone knows how to set ImageSource to null in xaml.
Something like this
<ImageSource x:Key="tt">null</ImageSource>
thanks!
In XAML, that would be {x:Null} (see documentation)
You might have to use it a bit differently than in your example :
<YourControl x:Key="tt" Content="{x:Null}"></ImageSource>
Or use the actual property that you want to set to null instead of Content.
If you have an ImageSource property of your YourControl, that should be something like :
<YourControl ImageSource="{x:Null}">
You can assign a property to null in XAML like this:
Source="{x:Null}"
You can't create an instance of an ImageSource since it's an abstract class.
You could define a BitmapImage but then you to set either the UriSource or StreamSource property somehow.
Related
I'm making app with using Xamarin.forms.
I already asked question here.
How to set child of class' property with using xaml? (Xamarin.forms)
But I couldn't get right answer for this, or there may be no solution for that.
What I want to do is setting my class's view's property from ContentPage's XAML.
my class has some view like Image and else.
I searched and found that there is 'ControlTemplete'. But I'm not sure it's what I'm looking for.
And I also don't think putting BindableProperty and OnPropertyChangedDelegate codes for every property that I want to set is a best way.
Is there another better solution?
Thanks.
You can map XAML that is inside your control to a property using ContentProperty attribute.
[ContentProperty("MyContent")]
public class MyControl : ContentView
{
public View MyContent { get; set; }
}
And in XAML somthing like this
<local:MyControl>
<Grid></Grid>
</local:MyControl>
this limits you to only one property but should work with any types.
I want to bind a Control's canvas.zindexproperty to a class property name zindex.
I tried this but it is not working
Binding zIndexBinding = new Binding("zIndex");
indicator.SetValue(Canvas.ZIndexProperty, zIndexBinding);
i have no idea how to do this, so any help will be appreciated. thank you
SetValue is to set a simple value rather than a binding. You can use instead SetBinding when using a Binding:
indicator.SetBinding(Canvas.ZIndexProperty, zIndexBinding);
Be aware that you'll need as well as the Path, which you've supplied, a Source, ElementName, or DataContext etc to resolve the object to which the path applies.
In WPF how do I set the ValidatesOnDataErrors property for the binding on a control (e.g. a TextBox)? Is this possible?
Thanks!
It's just a property of the Binding class. You can construct bindings in code, set the property and use SetBinding on the TextBox.
You can use GetBinding to get existing bindings, but you cannot modify them once they are in use...
Remember that ValidatesOnDataErrors is a property of a binding, not of a control.
So look for the correct binding of the control (in my example, the TextProperty dependency property)...
Try this:
System.Windows.Data.BindingExpression binding = this.textBox1.GetBindingExpression(System.Windows.Controls.TextBox.TextProperty);
binding.ParentBinding.ValidatesOnDataErrors = true;
I want to add a DependencyObject to a control from code behind. I have searched and searched online for how to do this with absolutely no success. The DependencyObject has a DependencyProperty. I also want to set this property from code-behind.
charting:ChartBehaviors inherits directly from DependencyObject. It is a class I wrote myself. The Chart control is a Third-party control.
charting:ChartBehaviors.FloatingTooltip is the DependencyProperty. This is also a class I wrote myself.
Here is what it looks like in XAML. I want to do this in code behind so that I can turn on and off the "behavior".
<charting:Chart>
<charting:ChartBehaviors.FloatingTooltip>
<charting:FloatingTooltipBehavior
TooltipTemplate="{StaticResource tooltipTemplate}" />
</charting:ChartBehaviors.FloatingTooltip>
</charting:Chart>
You can just use the SetValue method on the object (assuming you give your chart an id of chart1).
var behave = new FloatingTooltipBehavior();
chart1.SetValue(ChartBehaviors.FloatingTooltipProperty, behave);
Another solution would be to just add an Enabled property to your behavior and then set that from the code behind.
Well, you basically instantiate necessary dependency object and use appropriate method to add it to the control. For example, to add TextBlock to the StackPanel, you write it like this:
TextBlock txtMyText = new TextBlock();
stackPanel.Children.Add(txtMyText);
If you're wanting to add certain behavior to a chart, you should just get your chart object in code and look for a property like Behaviors or something. Then you either assign a behavior (if it's one-behavior-only) or add it like to the stackpanel:
Chart myChart;
myChart.Behavior = new FloatingTooltipBehavior();
It's hard to tell the exact syntax without knowing the component.
I'm moving project from Silverlight to WPF and I've come across a problem.
I have a control with an INotifyPropertyChanged property GeoRect of type GeoRect. GeoRect has a variety of public properties that are set in its constructor each of type IGeoPosition.
I am setting a binding to one of these properties like so:
<TextBlock Text="{Binding GeoRect.TopRight, ElementName=x_SomeControl}"></TextBlock>
In Silverlight the default ToString method is called on IGeoPosition instance every time the GeoRect property changes. In Wpf I don't get any text at all.
I can correct this in Wpf by adding a ValueConverter to the TextBlock which simply calls the ToString method on the object, but this appears to be unnecessary fat. Can anyone help?
I suspect that there is another problem in your binding. Also in WPF, data binding calls the ToString() method to build the text of a Text-control.
Have you checked the output window of visual studio for a binding error? Or maybe the GeoRect-class does not support INotifyPropertyChanged for the TopRight property?
I guess that ElementName=x_SomeControl and GeoRect.TopRight are causing a probable "Source and Path" comination error. Are you sure your x_SomeControl has a property called 'GeoRect'? Also is x_SomeControl.GeoRect not null? And x_SomeControl.GeoRect.TopRight has a correct value?
As HCL pointed out, this will become apparent when you view your Output window where BindingExpression error must have appeared for this binding.
Please check.