Converter/Markup with parameter
if you want a converter/markup and using constructor and parameter
this is a converter/markup for divid value received by parameter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[ValueConversion(typeof(double), typeof(double))] public class DivideConverter : MarkupExtension, IValueConverter { public override object ProvideValue(IServiceProvider serviceProvider) => this; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => (double)value / Divid; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); [ConstructorArgument("Divid")] public double Divid { get; set; } = 2; public DivideConverter() { } public DivideConverter(double divid) => Divid = divid; } |
and usage
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<Grid Width="50" Height="50"> <Line x:Name="PART_Center" Stroke="Red" X1="0" X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" Y1="{Binding ActualHeight, RelativeSource={RelativeSource Self}, Converter={local:DivideConverter 2}}" Y2="{Binding Y1, RelativeSource={RelativeSource Self}}" SnapsToDevicePixels="true" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" StrokeThickness="1"/> </Grid> |
and set line at the center of the control (grid)
Categories: Non classé
Commentaires récents