I have a two screens on my application each with same component of map. The layers of the map are stored as two list objects with simple ids of the layers representing the visible layers on each screen
<CheckBox
VerticalAlignment="Center"
Margin="3"
IsChecked="{Binding Visible}"
ToolTip="Layer visibility"
Checked="Visible_Changed"
Unchecked="Visible_Changed"
/>
As the user navigates between the two screens the visible property of the layer gets triggered from code behind and the checkbox reflects the same. The layers behave as they should as well.
The problem is that now the user may select one of the layers on any screen as change the visible property of the layer, in which case I have to update the layer list of that screen.
Is there any way I can make the checkbox not trigger the event when the visible property is changed by the code. I only want the event to trigger when user checks the check box
While you can't stop the event from being fired, you can encapsulate the code in the handler with a check for a bool
flag, which you set to true
when manually calling the code:
<CheckBox Checked="CheckBoxChanged" Unchecked="CheckBoxChanged" />
...
private void CheckBoxChanged(object sender, RoutedEventArgs e)
{
if (!isNotLocalChange)
{
// the user changed the Checked value
}
}
elsewhere...
isNotLocalChange = true;
// Do your programmatic change here
isNotLocalChange = false;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.