Для kotlin можно использовать ниже кода.
fun isMyServiceRunning(calssObj: Class<SERVICE_CALL_NAME>): Boolean {
val manager = requireActivity().getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
for (service in manager.getRunningServices(Integer.MAX_VALUE)) {
if (calssObj.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Для этого есть несколько способов:
Вы можете сделать свой стиль по умолчанию для всех TreeViewItems:
<Style TargetType="{x:Type TreeViewItem}">
...
</Style>
Разница в том, что вы не устанавливаете атрибут x: Key, а вы устанавливаете атрибут TargetType. В этом случае вам не нужно устанавливать ItemContainerStyle в TreeView.
<TreeView>
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource Style1}"/>
</TreeView.Resources>
</TreeView>
В этом случае вам также не нужно устанавливать ItemContainerStyle в TreeView.
Вы также можете изменить свой стиль следующим образом
<Style x:Key="Style1" TargetType="{x:Type TreeViewItem}">
<Setter Property="ItemContainerStyle" Value="{StaticResource Style1}"/>
</Style>
В этом случае вам все равно придется установить ItemContainerStyle в своем TreeView.