1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-26 06:49:19 +00:00

Experiment with a ListView style

I'm trying to make the ListView look like the old owner-drawn
WinForms UI.  The tricky bit is getting long comments and notes to
start in column 5 (label) and extend across multiple columns.

This approach sort of works, though it's currently incomplete, e.g.
the selection highlight style apparently gets dropped.
This commit is contained in:
Andy McFadden 2019-05-11 17:36:50 -07:00
parent f3f4c44633
commit bca1585571
3 changed files with 81 additions and 3 deletions

View File

@ -280,8 +280,12 @@ namespace SourceGenWPF {
/// </summary>
private FormattedParts GetEntry(int index) {
Debug.WriteLine("GEN " + index);
return FormattedParts.Create("off" + index, "addr" + index, "12 34",
"vncidmx", "", "yup:", "LDA", "$1234", "a & b");
if ((index % 10) != 0) {
return FormattedParts.Create("off" + index, "addr" + index, "12 34",
"vncidmx", "", "yup:", "LDA", "$1234", "a & b");
} else {
return FormattedParts.Create("offN This is a long comment line");
}
}
public class FormattedParts {
@ -294,6 +298,7 @@ namespace SourceGenWPF {
public string Opcode { get; private set; }
public string Operand { get; private set; }
public string Comment { get; private set; }
public bool SingleLine { get; private set; }
// Construct with factory methods.
private FormattedParts() { }
@ -311,6 +316,15 @@ namespace SourceGenWPF {
parts.Opcode = opcode;
parts.Operand = operand;
parts.Comment = comment;
parts.SingleLine = false;
return parts;
}
public static FormattedParts Create(string longComment) {
FormattedParts parts = new FormattedParts();
parts.Comment = longComment;
parts.SingleLine = true;
return parts;
}

View File

@ -215,9 +215,27 @@ limitations under the License.
</StackPanel>
</Grid>
<!--
ListView tweaks from https://stackoverflow.com/a/4472061/294248 . This is
necessary to get long comments and notes to start in the Label column. The
approach feels a little wobbly, but it seems to work.
MSFT GridViewRowPresenter example is promising, but I haven't figured out how to
make long-comment rows follow the same header (maybe manual update in code-behind?).
https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.gridviewrowpresenter?view=netframework-4.8
(in examples: snippets\csharp\VS_Snippets_Wpf\ListViewItemStyleSnippet)
https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/how-to-display-data-by-using-gridviewrowpresenter
Item Template Selectors are another possibility, maybe?
https://stackoverflow.com/q/5416946/294248
Getting more custom:
-->
<ListView Name="codeListView" Grid.Column="2"
FontFamily="{StaticResource GeneralMonoFont}"
Visibility="{Binding Path=CodeListVisibility}">
Visibility="{Binding Path=CodeListVisibility}"
VirtualizingStackPanel.VirtualizationMode="Recycling" >
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn Header="Offset" DisplayMemberBinding="{Binding Offset}"/>
@ -231,6 +249,49 @@ limitations under the License.
<GridViewColumn Header="Comment" DisplayMemberBinding="{Binding Comment}"/>
</GridView>
</ListView.View>
<!-- https://stackoverflow.com/a/4472061/294248 -->
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<DataTrigger Binding="{Binding SingleLine}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=codeListView, Path=View.Columns[0].ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=codeListView, Path=View.Columns[1].ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=codeListView, Path=View.Columns[2].ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=codeListView, Path=View.Columns[3].ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=codeListView, Path=View.Columns[4].ActualWidth}"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="5" Padding="8,2" Text="{Binding Comment}"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
<!--
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Grid>
<GridViewRowPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
-->
</Style>
</ListView.ItemContainerStyle>
</ListView>
<Grid Name="RightPanel" Grid.Column="4">

View File

@ -47,6 +47,9 @@ namespace SourceGenWPF.ProjWin {
mUI = new MainController(this);
codeListView.ItemsSource = new DisplayList(500);
GridView gv = (GridView)codeListView.View;
//gv.Columns[0].Width = 50;
}