이 경우 사용자가 일부 UIElement를 클릭 할 때이 요소를 대시 테두리로 둘러싸 기 바랍니다. 다른 객체가 있으면이 코드가 먼저 제거합니다.wp7, silverlight, 왜 이벤트가 두 번 발생합니까?
모든 것이 좋지만 "private void activateElem"은 두 번 발생하며 그 이유는 모르겠습니다. 어쩌면 누군가가 도울 수 있습니다. 나는 더 이상 아이디어가 없습니다.
누구나 이런 문제를 디버깅하는 데 도움이되는 아이디어가 있습니까? 어쩌면 모든 이벤트 대기열을 인쇄 할 수있는 방법이 있습니다. 이 실버 스파이는하지만 난 그게 Windows Phone 용 7
내 코드가 작동하지 않습니다 생각 : 난 정말 부품 및 미국 모델에보고 조언을 줄
public class ManipulationEngine
{
private Canvas sheet;
private static FrameworkElement current_active_element;
public ManipulationEngine(Canvas sheet)
{
this.sheet = sheet;
foreach (FrameworkElement elem in sheet.Children)
{
elem.MouseLeftButtonUp += new MouseButtonEventHandler(activateElem);
}
}
private void activateElem(object sender, MouseButtonEventArgs e)
{
FrameworkElement elem = sender as FrameworkElement;
if (current_active_element != null)
{
desactivateElem();
}
Grid grid = new Grid();
Rectangle recentagle = new Rectangle();
grid.SetValue(Canvas.TopProperty, (double)elem.GetValue(Canvas.TopProperty) - 10);
grid.SetValue(Canvas.LeftProperty, (double)elem.GetValue(Canvas.LeftProperty) - 10);
DoubleCollection stroke = new DoubleCollection();
stroke.Add(4);
stroke.Add(2);
recentagle.StrokeDashArray = stroke;
grid.Children.Add(recentagle);
sheet.Children.Remove(elem);
elem.Margin = new Thickness(10);
grid.Children.Add(elem);
sheet.Children.Add(grid);
current_active_element = elem;
}
private void desactivateElem()
{
if (current_active_element != null)
{
Grid grid = VisualTreeHelper.GetParent(current_active_element) as Grid;
grid.Children.Remove(current_active_element);
sheet.Children.Remove(grid);
current_active_element.SetValue(Canvas.TopProperty, (double)grid.GetValue(Canvas.TopProperty) + 10);
current_active_element.SetValue(Canvas.LeftProperty, (double)grid.GetValue(Canvas.LeftProperty) + 10);
current_active_element.Margin = new Thickness(0);
sheet.Children.Add(current_active_element);
current_active_element = null;
}
}
나는 해결책을 찾은 것 같아요. FrameworkElement를 클릭하면 이벤트가 발생합니다. 그런 다음 Canvas에서 FrameworkElement를 제거하고 그리드에 추가하고 그리드를 Canvas에 추가합니다. 해결책은 "e.Handled = true;"입니다. 이제 작동합니다 :) 그래서 FrameworkElement가 트리에서 더 깊어 져서 어떻게 든 다시 발생합니다. –
답변으로 추가하고 며칠 후에 수락하십시오. 다른 사람들이 같은 문제를 겪는다면 해결책을 제시 할 것입니다. – ChrisF