내 코드에 도움이 필요합니다. 나는 내가 UWP 윈도우 10 응용 프로그램을 만들었습니다 지금까지 UWP App 동적 피벗 MVVM 항상 viewmodel의 새 인스턴스를 만듭니다.
아래 그림처럼 레이아웃을 달성하기 위해 노력하고있어 그리고 내가 Vb.net하지만 C#을 사용하고 있습니다
아래 다음과 같습니다 또한 환영 받는다. Mvvm 패턴을 따르려고하고 추가 mvvm 프레임 워크 (xaml 동작 만 사용)를 사용하려고 시도합니다.
최종 목표는 페이지를 두 번 클릭 한 다음 페이지 이름에 헤더 바인딩을 사용하여 새 탭을 만드는 것입니다. 테스트 목적으로 더블 클릭이 올바르게 작동하지 않기 때문에 추가 페이지를 추가하고 탭 버튼을 추가했습니다. 탭의 컬렉션에 새 항목이 추가 될 때마다 데이터 템플릿이 필자가 원치 않는 내 viewmodel의 새 인스턴스를 만들기 때문에 UI에 반영되지 않습니다. 임시 추가 버튼은 올바른 메소드를 호출하고 더블 클릭으로 달성하고자하는 기능을 수행합니다. 아쉽게도 내 코드의 가장 짧은 예제를 게시하십시오.
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1">
<Button Width="200" VerticalAlignment="Stretch" Content="Add Page" Foreground="White">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Click">
<Core:CallMethodAction MethodName="AddPage" TargetObject="{Binding Mode=OneWay}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Button>
<Button Width="200" VerticalAlignment="Stretch" Content="Add Tab" Foreground="White">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Click">
<Core:CallMethodAction MethodName="AddSection" TargetObject="{Binding Mode=OneWay}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Button>
</StackPanel>
<Pivot Grid.Column="1" Grid.Row="2" Foreground="White" ItemsSource="{Binding PivotItems, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Foreground="White"/>
</DataTemplate>
</Pivot.HeaderTemplate>
<Pivot.ItemTemplate>
<DataTemplate>
<GridView ItemsSource="{Binding Result, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="DoubleTapped">
<Core:CallMethodAction MethodName="AddSection"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<GridView.ItemTemplate>
<DataTemplate>
<Grid x:Name="CanvasControl" Background="#00000000" Width="200" Height="200" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="8*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="11*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Canvas Grid.Column="1" Grid.Row="1" Margin="10" Background="White" DoubleTapped="Canvas_DoubleTapped" />
<TextBox Grid.Column="1" Grid.Row="2" Foreground="White" FontSize="14" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Padding="0" Background="{x:Null}" BorderBrush="{x:Null}" Text="{Binding CanvasCollection[0].CanvasName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Column="1" Grid.Row="0" Foreground="White" FontSize="12" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="10" IsHitTestVisible="False" Text="{Binding CanvasCollection[0].CanvasMaster}" />
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</DataTemplate>
</Pivot.ItemTemplate>
</Pivot>
</Grid>
뷰 모델
Public Class ProjectDataViewModel
Implements INotifyPropertyChanged
Private WindowData As New CanvasData
Private randomdata As New DataGenerators
Private m_PivotItems As New ObservableCollection(Of PivotSection)
Private Canvas_Collection As New ObservableCollection(Of CanvasData)
Private mycollection As New CanvasData
Private pivotItem_Home As New PivotSection() With {.Name = "Home"}
Private Sub NotifyPropertyChanged(Optional propertyName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Property PropertyCollectionItemName As String
Get
Return WindowData.CanvasName
End Get
Set(value As String)
WindowData.CanvasName = value
End Set
End Property
Public Property PropertyCollectionItemMaster As String
Get
Return WindowData.CanvasMaster
End Get
Set(value As String)
WindowData.CanvasMaster = value
End Set
End Property
Public Property CanvasCollection As ObservableCollection(Of CanvasData)
Get
Return Canvas_Collection
End Get
Private Set(value As ObservableCollection(Of CanvasData))
Canvas_Collection = value
NotifyPropertyChanged()
End Set
End Property
Public Property my_collection As CanvasData
Get
Return mycollection
End Get
Set(value As CanvasData)
mycollection = value
NotifyPropertyChanged()
End Set
End Property
Public Property PivotItems() As ObservableCollection(Of PivotSection)
Get
Return m_PivotItems
End Get
Set
m_PivotItems = Value
NotifyPropertyChanged()
End Set
End Property
Public Sub AddSection()
Dim pivotItem_New As New PivotSection() With {.Name = "Item Header " + PivotItems.Count.ToString}
m_PivotItems.Add(pivotItem_New)
End Sub
Public Sub AddPage()
Dim Newpage As New PivotItemContent
Newpage.CanvasCollection.Add(New CanvasData With {.CanvasName = "Page " + pivotItem_Home.Result.Count.ToString, .CanvasMaster = "Master "})
pivotItem_Home.Result.Add(newpage)
End Sub
Sub New()
Dim indexPage As New PivotItemContent
PivotItems = New ObservableCollection(Of PivotSection)
PivotItems.Add(pivotItem_Home)
indexPage.CanvasCollection.Add(New CanvasData With {.CanvasName = "Home", .CanvasMaster = "Master"})
pivotItem_Home.Result.Add(indexPage)
End Sub
PivotSection 클래스
End Class
Public Class PivotSection
Implements INotifyPropertyChanged
Private Sub NotifyPropertyChanged(Optional propertyName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Property Name() As String
Get
Return m_Name
End Get
Set
m_Name = Value
End Set
End Property
Private m_Name As String
Public Property SystemLabel() As String
Get
Return m_SystemLabel
End Get
Set
m_SystemLabel = Value
End Set
End Property
Private m_SystemLabel As String
Public Property Result() As ObservableCollection(Of PivotItemContent)
Get
Return m_Result
End Get
Set
m_Result = Value
NotifyPropertyChanged()
End Set
End Property
Private m_Result As New ObservableCollection(Of PivotItemContent)
'Public Sub New()
' Result = New ObservableCollection(Of PivotGroup)
'End Sub
End Class
PivotContent 클래스
Public Class PivotItemContent
Implements INotifyPropertyChanged
Private Sub NotifyPropertyChanged(Optional propertyName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Canvas_Collection As New ObservableCollection(Of CanvasData)
Public Property CanvasCollection As ObservableCollection(Of CanvasData)
Get
Return Canvas_Collection
End Get
Private Set(value As ObservableCollection(Of CanvasData))
Canvas_Collection = value
NotifyPropertyChanged()
End Set
End Property
Private Page_Name As String
Public Property PageName As String
Get
Return Page_Name
End Get
Set(value As String)
Page_Name = value
NotifyPropertyChanged()
End Set
End Property
Private Page_Master As String
Public Property PageMaster As String
Get
Return Page_Master
End Get
Set(value As String)
Page_Master = value
NotifyPropertyChanged()
End Set
End Property
End Class
CavasDataclass
Imports Windows.UI
Public Class CanvasData
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(Optional propertyName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Private _CanvasMaster_Name As String
Private _CanvasName As String
Public Property CanvasMaster() As String
Get
Return _CanvasMaster_Name
End Get
Set(ByVal value As String)
_CanvasMaster_Name = value
NotifyPropertyChanged()
End Set
End Property
Public Property CanvasName As String
Get
Return _CanvasName
End Get
Set(value As String)
_CanvasName = value
NotifyPropertyChanged()
End Set
End Property
End Class