잘 알려진 Calculator 예제의 자체 버전을 구현하여 MEF 프레임 워크로 작업하는 것을 익히려고합니다. 사용자 인터페이스는 WPF입니다.합성 후 창에 InputBindings를 추가하는 방법은 무엇입니까?
Viewmodel은보기에서 의 'ListBox'로 표시되는 ObservableCollection(Of IOperation)
을 보유하고 있습니다. 각 Button
의 텍스트는 Symbol
이라는 속성으로 IOperation
에 정의 된 Char
입니다. ListBox의 SelectedItem을 ViewModel의 속성에 바인딩하면 Button
을 눌렀을 때 현재 IOperation
의 Calculate
메서드를 실행할 수 있습니다. (아래 코드는 이것을 설명.)
을하지만, 지금은 각 KeyBinding
이 IOperation
에 정의 된 Symbol
와 연결됩니다보기에 InputBindings
를 추가해야합니다. (switch
) 문을 구현하여 Viewmodel의 IOperation
콜렉션을 반복하여 'Calculate'메소드를 호출해야하는 것을 선택하는 것을 피할 수없는 것 같습니다.
아이디어가 있으십니까?
XAML :
<ListBox Grid.Column="1" Grid.Row="3" Name="OperationsList"
SelectedItem="{Binding ActiveOperation,Mode=TwoWay}"
ItemsSource="{Binding Operations}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Symbol}"
ToolTip="{Binding Description}"
Command="{Binding ElementName=OperationsList, Path=DataContext.ActivateOperation}"
Click="Button_Click_1"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
IOPERATION :
Public Interface IOperation
Function Calculate() As Double
Property Left As Double
Property Right As Double
Property Symbol As String
Property Description As String
End Interface
의 ViewModel : 가장자리가 있으므로 적절하게 조절에 대해
Private _activateOperation As Command
Public Property ActivateOperation As Command
Get
Return _activateOperation
End Get
Set(value As Command)
_activateOperation = value
OnPropertyChanged()
End Set
End Property
Public Property ActiveOperation As IOperation
Get
Return _compositor.ActiveOperation
End Get
Set(value As ICalculator)
_compositor.ActiveOperation = value
OnPropertyChanged()
End Set
End Property
Public ReadOnly Property Operations As ObservableCollection(Of IOperation)
Get
Return New ObservableCollection(Of ICalculator)(_compositor.Operations)
End Get
End Property
Private Sub DoActivateOperation(Optional parameter As Object = Nothing)
If Left.HasValue Then
MakeCalculation()
Else
Left = CDbl(Display)
ClearDisplay()
End If
End Sub
감사합니다. 그러나 KeyBindings는 일반적으로 Ctrl 키의 Alt 키를 눌러야하기 때문에 대부분의 기호에는 작동하지 않습니다. – Dabblernl