style: Use switch expression in vs col view_factory
This commit is contained in:
1 parent
7ff2850b2d
commit
6d5e9eb94e
1 file changed
+56
-51
@@ -44,60 +44,65 @@ namespace mbts.spark.VolSurface {
|
||||
ValueConverter.create<VolSurfaceRowContext, object>(row => row?.get_cell(model));
|
||||
|
||||
public override FrameworkElement view_factory() {
|
||||
switch (type) {
|
||||
case VolSurfaceColumnType.RowHeader: {
|
||||
var view = new TextBlock {
|
||||
FontWeight = FontWeights.Bold
|
||||
};
|
||||
view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolSurfaceRowContext.expiration)));
|
||||
return view;
|
||||
}
|
||||
case VolSurfaceColumnType.ReadOnly: {
|
||||
var view = new TextBlock {
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
Margin = _cell_padding,
|
||||
Foreground = Brushes.Blue,
|
||||
};
|
||||
view.SetBinding(FrameworkElement.DataContextProperty, new Binding() {
|
||||
Converter = _data_context_converter
|
||||
});
|
||||
view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolGridCellVM.candidate_value)) {
|
||||
Converter = ValueConverter.create(obj => model.format(obj))
|
||||
});
|
||||
return view;
|
||||
}
|
||||
case VolSurfaceColumnType.ReadWriteTick: {
|
||||
var view = new VolSurfaceCellView {
|
||||
HorizontalContentAlignment = HorizontalAlignment.Right,
|
||||
Padding = _cell_padding,
|
||||
};
|
||||
view.SetCurrentValue(DIYGrid.ColumnProperty, this);
|
||||
return type switch {
|
||||
VolSurfaceColumnType.RowHeader => row_header_cell(),
|
||||
VolSurfaceColumnType.ReadOnly => read_only_cell(),
|
||||
VolSurfaceColumnType.ReadWriteTick => read_write_cell(),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
view.CommandBindings.Add(new CommandBinding(VolSurfaceCellView.BeginEditCommand, VolSurfaceCellView.BeginEditExecuted));
|
||||
view.CommandBindings.Add(new CommandBinding(VolSurfaceCellView.EndEditCommand, VolSurfaceCellView.EndEditExecuted));
|
||||
view.CommandBindings.Add(new CommandBinding(VolSurfaceCellView.CancelEditCommand, VolSurfaceCellView.CancelEditExecuted));
|
||||
FrameworkElement row_header_cell() {
|
||||
var view = new TextBlock {
|
||||
FontWeight = FontWeights.Bold,
|
||||
};
|
||||
view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolSurfaceRowContext.expiration)));
|
||||
return view;
|
||||
}
|
||||
|
||||
view.InputBindings.Add(new MouseBinding(VolSurfaceCellView.BeginEditCommand, new MouseGesture(MouseAction.LeftClick)));
|
||||
view.InputBindings.Add(new KeyBinding(VolSurfaceCellView.EndEditCommand, new KeyGesture(Key.Return)));
|
||||
view.InputBindings.Add(new KeyBinding(VolSurfaceCellView.CancelEditCommand, new KeyGesture(Key.Escape)));
|
||||
FrameworkElement read_only_cell() {
|
||||
var view = new TextBlock {
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
Margin = _cell_padding,
|
||||
Foreground = Brushes.Blue,
|
||||
};
|
||||
view.SetBinding(FrameworkElement.DataContextProperty, new Binding() {
|
||||
Converter = _data_context_converter
|
||||
});
|
||||
view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolGridCellVM.candidate_value)) {
|
||||
Converter = ValueConverter.create(obj => model.format(obj))
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
view.SetBinding(FrameworkElement.DataContextProperty, new Binding() {
|
||||
Converter = _data_context_converter
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.CommittedValueProperty, new Binding(nameof(VolGridCellVM.committed_value)) {
|
||||
Mode = BindingMode.OneWay,
|
||||
Converter = ValueConverter.create(obj => model.format(obj))
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.CandidateValueProperty, new Binding(nameof(VolGridCellVM.candidate_value)) {
|
||||
Mode = BindingMode.TwoWay,
|
||||
Converter = ValueConverter.create<object, string>(obj => model.format(obj), obj => model.parse(obj))
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.TickDownCommandProperty, new Binding(nameof(VolGridTickCellVM.tick_down_cmd)));
|
||||
view.SetBinding(VolSurfaceCellView.TickUpCommandProperty, new Binding(nameof(VolGridTickCellVM.tick_up_cmd)));
|
||||
return view;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
FrameworkElement read_write_cell() {
|
||||
var view = new VolSurfaceCellView {
|
||||
HorizontalContentAlignment = HorizontalAlignment.Right,
|
||||
Padding = _cell_padding,
|
||||
};
|
||||
view.SetCurrentValue(DIYGrid.ColumnProperty, this);
|
||||
|
||||
view.CommandBindings.Add(new CommandBinding(VolSurfaceCellView.BeginEditCommand, VolSurfaceCellView.BeginEditExecuted));
|
||||
view.CommandBindings.Add(new CommandBinding(VolSurfaceCellView.EndEditCommand, VolSurfaceCellView.EndEditExecuted));
|
||||
view.CommandBindings.Add(new CommandBinding(VolSurfaceCellView.CancelEditCommand, VolSurfaceCellView.CancelEditExecuted));
|
||||
|
||||
view.InputBindings.Add(new MouseBinding(VolSurfaceCellView.BeginEditCommand, new MouseGesture(MouseAction.LeftClick)));
|
||||
view.InputBindings.Add(new KeyBinding(VolSurfaceCellView.EndEditCommand, new KeyGesture(Key.Return)));
|
||||
view.InputBindings.Add(new KeyBinding(VolSurfaceCellView.CancelEditCommand, new KeyGesture(Key.Escape)));
|
||||
|
||||
view.SetBinding(FrameworkElement.DataContextProperty, new Binding() {
|
||||
Converter = _data_context_converter
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.CommittedValueProperty, new Binding(nameof(VolGridCellVM.committed_value)) {
|
||||
Mode = BindingMode.OneWay,
|
||||
Converter = ValueConverter.create(obj => model.format(obj))
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.CandidateValueProperty, new Binding(nameof(VolGridCellVM.candidate_value)) {
|
||||
Mode = BindingMode.TwoWay,
|
||||
Converter = ValueConverter.create<object, string>(obj => model.format(obj), obj => model.parse(obj))
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.TickDownCommandProperty, new Binding(nameof(VolGridTickCellVM.tick_down_cmd)));
|
||||
view.SetBinding(VolSurfaceCellView.TickUpCommandProperty, new Binding(nameof(VolGridTickCellVM.tick_up_cmd)));
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user