Skip to content

Commit b6efd30

Browse files
committed
Allow modify node header and footer ContentPresenter style
1 parent 3f17293 commit b6efd30

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

NodifyM.Avalonia.Example/MainWindow.axaml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,25 @@
126126
<controls:Node x:Name="Node"
127127
IsResize="True"
128128
Input="{Binding Input}"
129-
Header="{Binding Title}"
129+
130130
Location="{Binding Location,Mode=TwoWay}"
131131
VerticalAlignment="Center"
132132
Output="{Binding Output}">
133+
<controls:Node.Styles>
134+
<Style Selector="controls|Node /template/ ContentPresenter#HeaderContentPresenter">
135+
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
136+
</Style>
137+
</controls:Node.Styles>
138+
<controls:Node.Header>
139+
<Grid HorizontalAlignment="Stretch">
140+
<Grid.ColumnDefinitions>
141+
<ColumnDefinition Width="*" />
142+
<ColumnDefinition Width="*" />
143+
</Grid.ColumnDefinitions>
144+
<TextBlock Grid.Column="0" VerticalAlignment="Center" Text="Left Content" />
145+
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding Title}" />
146+
</Grid>
147+
</controls:Node.Header>
133148
<controls:Node.Styles>
134149
<Style Selector="controls|Node[IsSelected=False]:pointerover">
135150
<Setter Property="BorderBrush" Value="AliceBlue"></Setter>
@@ -142,14 +157,7 @@
142157
VerticalAlignment="Center"
143158
IsConnected="{Binding IsConnected}"
144159
Anchor="{Binding Anchor, Mode=OneWayToSource}">
145-
<controls:NodeInput.Header>
146-
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"
147-
HorizontalAlignment="Right">
148-
149-
<TextBlock VerticalAlignment="Center" x:Name="textBlock"
150-
Text="{Binding Title}" />
151-
</StackPanel>
152-
</controls:NodeInput.Header>
160+
153161
<controls:NodeInput.BorderBrush>
154162
<SolidColorBrush
155163
Color="CornflowerBlue"
@@ -167,12 +175,14 @@
167175
IsConnected="{Binding IsConnected}"
168176
Anchor="{Binding Anchor, Mode=OneWayToSource}">
169177
<controls:NodeOutput.Header>
170-
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"
171-
HorizontalAlignment="Right">
172-
173-
<TextBlock VerticalAlignment="Center" x:Name="textBlock"
174-
Text="{Binding Title}" />
175-
</StackPanel>
178+
<Grid>
179+
<Grid.ColumnDefinitions>
180+
<ColumnDefinition Width="*" />
181+
<ColumnDefinition Width="*" />
182+
</Grid.ColumnDefinitions>
183+
<TextBlock Grid.Column="0" VerticalAlignment="Center" Text="Left Content" />
184+
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding Title}" />
185+
</Grid>
176186
</controls:NodeOutput.Header>
177187
<controls:NodeOutput.BorderBrush>
178188
<SolidColorBrush

NodifyM.Avalonia/Controls/Node.axaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
CornerRadius="3 3 0 0"
7777
Grid.ColumnSpan="3"
7878
Padding="6 4 6 4">
79-
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Header}" />
79+
<ContentPresenter Name="HeaderContentPresenter" Content="{TemplateBinding Header}" />
8080
</Border>
8181

8282
<!--Body-->
@@ -115,7 +115,7 @@
115115
Grid.Row="2"
116116
Grid.ColumnSpan="3"
117117
Padding="6 4 6 4">
118-
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Footer}" />
118+
<ContentPresenter Name="FooterContentPresenter" Content="{TemplateBinding Footer}" />
119119
</Border>
120120

121121
<!-- Hand -->
@@ -139,19 +139,22 @@
139139
</ControlTemplate>
140140
</Setter>
141141
</Style>
142+
<Style Selector="controls|Node ContentPresenter#HeaderContentPresenter">
143+
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
144+
</Style>
145+
<Style Selector="controls|Node ContentPresenter#FooterContentPresenter">
146+
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
147+
</Style>
142148
<Style Selector="controls|Node[IsSelected=False]:pointerover">
143149
<Setter Property="BorderBrush" Value="LightBlue"></Setter>
144-
145150
</Style>
146151
<Style Selector="controls|Node[IsSelected=True]">
147152
<Setter Property="BorderBrush" Value="Orange"></Setter>
148153
</Style>
149154
<Style Selector="controls|Node[IsSelected=True][IsResize=True]">
150155
<Style Selector="^ /template/Thumb">
151156
<Setter Property="IsVisible" Value="True"/>
152-
153157
</Style>
154-
155158
</Style>
156159

157160

0 commit comments

Comments
 (0)