Skip to content

Commit 014a143

Browse files
csharpfritzCopilot
andcommitted
fix: TreeView caret not rotating on expand/collapse (FritzAndFriends#361)
The NodeImage property's fallback paths (when ShowLines=false) did not check ShowExpandCollapse, relying solely on ImageSet.Collapse being non-empty. This made the logic fragile and returned Default_NoExpand.gif for any ImageSet where Collapse was empty, even when ShowExpandCollapse was true. Restructured NodeImage to: - Explicitly check ShowExpandCollapse in non-ShowLines code paths - Always return distinct expand/collapse images when ShowExpandCollapse=true - Fall back to Default_Collapse.gif / Default_Expand.gif when an ImageSet does not provide its own collapse/expand images - Return Default_NoExpand.gif only when ShowExpandCollapse is false Extracted ExpandCollapseImage() helper to DRY the ImageSet-to-filename resolution with guaranteed defaults. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6506080 commit 014a143

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

src/BlazorWebFormsComponents/TreeNode.razor.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ protected string NodeImage
191191
return $"{ImageLocation}Default_Dash.gif";
192192
}
193193

194-
return string.IsNullOrEmpty(ParentTreeView.ImageSet.Collapse) ? $"{ImageLocation}Default_NoExpand.gif" : (Expanded ? $"{ImageLocation}{ParentTreeView.ImageSet.Collapse}" : $"{ImageLocation}{ParentTreeView.ImageSet.Expand}");
195-
//return $"{ImageLocation}Default_NoExpand.gif";
194+
if (ParentTreeView.ShowExpandCollapse)
195+
{
196+
return Expanded ? $"{ImageLocation}{ExpandCollapseImage(true)}" : $"{ImageLocation}{ExpandCollapseImage(false)}";
197+
}
198+
199+
return $"{ImageLocation}Default_NoExpand.gif";
196200

197201
}
198202

@@ -209,11 +213,35 @@ protected string NodeImage
209213
return (Expanded ? $"{ImageLocation}Default_TCollapse.gif" : $"{ImageLocation}Default_TExpand.gif");
210214
}
211215

212-
return string.IsNullOrEmpty(ParentTreeView.ImageSet.Collapse) ? $"{ImageLocation}Default_NoExpand.gif" : (Expanded ? $"{ImageLocation}{ParentTreeView.ImageSet.Collapse}" : $"{ImageLocation}{ParentTreeView.ImageSet.Expand}");
216+
if (ParentTreeView.ShowExpandCollapse)
217+
{
218+
return Expanded ? $"{ImageLocation}{ExpandCollapseImage(true)}" : $"{ImageLocation}{ExpandCollapseImage(false)}";
219+
}
220+
221+
return $"{ImageLocation}Default_NoExpand.gif";
213222

214223
}
215224

216-
return string.IsNullOrEmpty(ParentTreeView.ImageSet.Collapse) ? $"{ImageLocation}Default_NoExpand.gif" : (Expanded ? $"{ImageLocation}{ParentTreeView.ImageSet.Collapse}" : $"{ImageLocation}{ParentTreeView.ImageSet.Expand}");
225+
return $"{ImageLocation}Default_NoExpand.gif";
226+
}
227+
}
228+
229+
/// <summary>
230+
/// Returns the appropriate expand or collapse image filename from the ImageSet,
231+
/// falling back to Default_Collapse.gif / Default_Expand.gif when the ImageSet
232+
/// does not provide one.
233+
/// </summary>
234+
private string ExpandCollapseImage(bool expanded)
235+
{
236+
if (expanded)
237+
{
238+
var collapse = ParentTreeView.ImageSet.Collapse;
239+
return !string.IsNullOrEmpty(collapse) ? collapse : "Default_Collapse.gif";
240+
}
241+
else
242+
{
243+
var expand = ParentTreeView.ImageSet.Expand;
244+
return !string.IsNullOrEmpty(expand) ? expand : "Default_Expand.gif";
217245
}
218246
}
219247

0 commit comments

Comments
 (0)