I'm trying to create a custom expand / collapse indicator for my tree items but there is one situation where it is not working: when the item has no children the indicator is wrong. I'm using the technique suggested in this forum post to fill my tree on demand.
I have tried two different approaches but neither one gives an accurate result.
1. Binding to IsExpanded:
I have created a value converter:
public
class
TreeIconConverter : IValueConverter
{
public
string
ExpandIcon {
get
;
set
; }
public
string
CollapseIcon {
get
;
set
; }
public
string
LeafIcon {
get
;
set
; }
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
if
(value
is
bool
expanded)
return
expanded ? CollapseIcon : ExpandIcon;
return
null
;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
throw
new
NotImplementedException();
}
}
and I'm using a Label as the custom tree indicator:
<
Label
HeightRequest
=
"24"
WidthRequest
=
"24"
HorizontalOptions
=
"Center"
VerticalOptions
=
"Center"
FontFamily
=
"{StaticResource IconFont}"
FontSize
=
"{StaticResource SelectionIconSize}"
Text
=
"{Binding IsExpanded, Converter={StaticResource TreeIconConverter}}"
/>
This gives the best result, but when the item has no children the ExpandIcon is shown.
2. Binding to TreeViewDataItem:
I have altered the value converter to try and detect when the item has children:
public
class
TreeIconConverter : IValueConverter
{
public
string
ExpandIcon {
get
;
set
; }
public
string
CollapseIcon {
get
;
set
; }
public
string
LeafIcon {
get
;
set
; }
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
if
(value
is
TreeViewDataItem item)
{
if
(!item.IsExpanded)
return
CollapseIcon;
if
(item.Item
is
LocationGroup group)
{
if
(group.HaveChildren && group.Children.Count == 0)
return
LeafIcon;
}
return
ExpandIcon;
}
return
null
;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
throw
new
NotImplementedException();
}
}
group.HaveChildren is true only after getting the group's children, if it's false we don't yet have the group's children in memory.
The Label has been changed to:
<Label HeightRequest=
"24"
WidthRequest=
"24"
HorizontalOptions=
"Center"
VerticalOptions=
"Center"
FontFamily=
"{StaticResource IconFont}"
FontSize=
"{StaticResource SelectionIconSize}"
Text=
"{Binding ., Converter={StaticResource TreeIconConverter}}"
/>
With this second version, all the items always show the CollapseIcon.
Does the TreeView support any kind of on demand update?
In other words: does it require the entire tree to be available on load, or can a node's children be made available only when expanding the node?
I have installed Xamarin UI and it give an error upon compilation...
/iOS/MTOUCH: Error MT2101: Can't resolve the reference 'System.Void ObjCRuntime.BlockLiteral::SetupBlockUnsafe(System.Delegate,System.Delegate)', referenced from the method 'System.Void TelerikUI.TKListView::PerformBatchUpdates(System.Action,System.Action`1<System.Boolean>)' in 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'. (MT2101) (iOS)
How do I fix this?
Hi,
I'm using XamarinForms and have a telerik listview and an entry on a page and am using the entry to filter the listview. I have the filter wired up to my ViewModel and it is working without issue. However, I now notice that the multiple section that is enabled does not persist after the filter is applied. And since the SelectedItems property cannot be bound in MVVM, I cannot easily re-apply those selected items. Is there a property/workaround that will allow that persistence?
I am trying to add an image to a button but I am having difficulty trying to align the image with the text.
I want some text with an image next to it - how can I align the image on a button?
Segmented control doesn't seem to support multi line text (separated by newline character).
Is there a way we can make this work? Is this something that can be added via a custom renderer for both ios and android?
Can the RadTabView have dynamically bound items using a ItemTemplate (like a ListView)?
If not, are there any workarounds?