Как видите, здесь есть функция перетаскивания. Все работает отлично, но когда я перетаскиваю TrainLeft или TrainRight, я вижу их только внутри ScrollView во время их перемещения. Я хочу видеть TrainLeft и TrainRight за пределами ScrollView, пока я их перемещаю. Я буду использовать StationMap внутри другого окна. Фактически, когда я использую Grid вместо ScrollView, это сработало. Поэтому, когда я использовал этот подход, он сработал, но мне нужно добавить MergeStationTrain автоматически.
public partial class StationMap : UserControl
{
public ObservableCollection DataList { get; } = new
ObservableCollection();
public MergeStationTrain this[int index]
{
get
{
return DataList[index];
}
set
{
DataList[index] = value;
}
}
public Database database { get; set; } = null;
public StationMap()
{
InitializeComponent();
DataContext = this;
}
public async Task UpdateMap()
{
DataList.Clear();
string query = QueryManager.GetQuery(QueryType.SelectAllStations);
List list = await database.GetTableAsync(query, tableName:
"t_station");
foreach (StationInfo item in list)
{
MergeStationTrain newItem = new MergeStationTrain()
{
StationName = item.stnName,
TrainName = item.stnNo,
ShowLeft = true,
ShowRight = true
};
DataList.Add(newItem);
}
}
}
public partial class TrainRight : UserControl
{
public static readonly DependencyProperty TrainNameProperty =
DependencyProperty.Register("TrainName", typeof(string), typeof(TrainRight));
public static readonly DependencyProperty ShowFireProperty =
DependencyProperty.Register("ShowFire", typeof(bool), typeof(TrainRight), new PropertyMetadata(false, ShowFirePropertyChanged));
public static readonly DependencyProperty ShowDoorProperty =
DependencyProperty.Register("ShowDoor", typeof(bool), typeof(TrainRight), new PropertyMetadata(false, ShowDoorPropertyChanged));
public bool ShowFire
{
get { return (bool)GetValue(ShowFireProperty); }
set { SetValue(ShowFireProperty, value); }
}
public bool ShowDoor
{
get { return (bool)GetValue(ShowDoorProperty); }
set { SetValue(ShowDoorProperty, value); }
}
public string TrainName
{
get { return (string)GetValue(TrainNameProperty); }
set { SetValue(TrainNameProperty, value); }
}
private ElementAdorner _elementAdorner = default!;
public TrainRight()
{
InitializeComponent();
DataContext = this;
MouseMove += DragControl_MouseMove;
PreviewGiveFeedback += DragControl_PreviewGiveFeedback;
}
private void DragControl_PreviewGiveFeedback(object sender, GiveFeedbackEventArgs e)
{
_elementAdorner.SetArrange(this);
}
private void DragControl_MouseMove(object sender, MouseEventArgs e)
{
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
_elementAdorner = new ElementAdorner(this);
adornerLayer.Add(_elementAdorner);
DragDrop.DoDragDrop(this, this.DataContext, DragDropEffects.Copy);
adornerLayer.Remove(_elementAdorner);
}
private static void ShowFirePropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainRight trainLeft = (TrainRight)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire,
(ImageSource)Application.Current.FindResource("FireGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imFire, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire, null);
}
}
private static void ShowDoorPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainRight trainLeft = (TrainRight)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor,
(ImageSource)Application.Current.FindResource("DoorGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imDoor, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor, null);
}
}
}
public partial class TrainLeft : UserControl
{
public static readonly DependencyProperty TrainNameProperty =
DependencyProperty.Register("TrainName", typeof(string), typeof(TrainLeft));
public static readonly DependencyProperty ShowFireProperty =
DependencyProperty.Register("ShowFire", typeof(bool), typeof(TrainLeft), new
PropertyMetadata(false, ShowFirePropertyChanged));
public static readonly DependencyProperty ShowDoorProperty =
DependencyProperty.Register("ShowDoor", typeof(bool), typeof(TrainLeft), new
PropertyMetadata(false, ShowDoorPropertyChanged));
public bool ShowFire
{
get { return (bool)GetValue(ShowFireProperty); }
set { SetValue(ShowFireProperty, value); }
}
public bool ShowDoor
{
get { return (bool)GetValue(ShowDoorProperty); }
set { SetValue(ShowDoorProperty, value); }
}
public string TrainName
{
get { return (string)GetValue(TrainNameProperty); }
set { SetValue(TrainNameProperty, value); }
}
private ElementAdorner _elementAdorner = default!;
public TrainLeft()
{
InitializeComponent();
DataContext = this;
MouseMove += DragControl_MouseMove;
PreviewGiveFeedback += DragControl_PreviewGiveFeedback;
}
private void DragControl_PreviewGiveFeedback(object sender, GiveFeedbackEventArgs e)
{
_elementAdorner.SetArrange(this);
}
private void DragControl_MouseMove(object sender, MouseEventArgs e)
{
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
_elementAdorner = new ElementAdorner(this);
adornerLayer.Add(_elementAdorner);
DragDrop.DoDragDrop(this, this.DataContext, DragDropEffects.Copy);
adornerLayer.Remove(_elementAdorner);
}
private static void ShowFirePropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainLeft trainLeft = (TrainLeft)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire,
(ImageSource)Application.Current.FindResource("FireGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imFire, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire, null);
}
}
private static void ShowDoorPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainLeft trainLeft = (TrainLeft)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor,
(ImageSource)Application.Current.FindResource("DoorGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imDoor, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor, null);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... ure-in-wpf
Функция перетаскивания в WPF ⇐ C#
Место общения программистов C#
1710823101
Гость
Как видите, здесь есть функция перетаскивания. Все работает отлично, но когда я перетаскиваю TrainLeft или TrainRight, я вижу их только внутри ScrollView во время их перемещения. Я хочу видеть TrainLeft и TrainRight за пределами ScrollView, пока я их перемещаю. Я буду использовать StationMap внутри другого окна. Фактически, когда я использую Grid вместо ScrollView, это сработало. Поэтому, когда я использовал этот подход, он сработал, но мне нужно добавить MergeStationTrain автоматически.
public partial class StationMap : UserControl
{
public ObservableCollection DataList { get; } = new
ObservableCollection();
public MergeStationTrain this[int index]
{
get
{
return DataList[index];
}
set
{
DataList[index] = value;
}
}
public Database database { get; set; } = null;
public StationMap()
{
InitializeComponent();
DataContext = this;
}
public async Task UpdateMap()
{
DataList.Clear();
string query = QueryManager.GetQuery(QueryType.SelectAllStations);
List list = await database.GetTableAsync(query, tableName:
"t_station");
foreach (StationInfo item in list)
{
MergeStationTrain newItem = new MergeStationTrain()
{
StationName = item.stnName,
TrainName = item.stnNo,
ShowLeft = true,
ShowRight = true
};
DataList.Add(newItem);
}
}
}
public partial class TrainRight : UserControl
{
public static readonly DependencyProperty TrainNameProperty =
DependencyProperty.Register("TrainName", typeof(string), typeof(TrainRight));
public static readonly DependencyProperty ShowFireProperty =
DependencyProperty.Register("ShowFire", typeof(bool), typeof(TrainRight), new PropertyMetadata(false, ShowFirePropertyChanged));
public static readonly DependencyProperty ShowDoorProperty =
DependencyProperty.Register("ShowDoor", typeof(bool), typeof(TrainRight), new PropertyMetadata(false, ShowDoorPropertyChanged));
public bool ShowFire
{
get { return (bool)GetValue(ShowFireProperty); }
set { SetValue(ShowFireProperty, value); }
}
public bool ShowDoor
{
get { return (bool)GetValue(ShowDoorProperty); }
set { SetValue(ShowDoorProperty, value); }
}
public string TrainName
{
get { return (string)GetValue(TrainNameProperty); }
set { SetValue(TrainNameProperty, value); }
}
private ElementAdorner _elementAdorner = default!;
public TrainRight()
{
InitializeComponent();
DataContext = this;
MouseMove += DragControl_MouseMove;
PreviewGiveFeedback += DragControl_PreviewGiveFeedback;
}
private void DragControl_PreviewGiveFeedback(object sender, GiveFeedbackEventArgs e)
{
_elementAdorner.SetArrange(this);
}
private void DragControl_MouseMove(object sender, MouseEventArgs e)
{
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
_elementAdorner = new ElementAdorner(this);
adornerLayer.Add(_elementAdorner);
DragDrop.DoDragDrop(this, this.DataContext, DragDropEffects.Copy);
adornerLayer.Remove(_elementAdorner);
}
private static void ShowFirePropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainRight trainLeft = (TrainRight)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire,
(ImageSource)Application.Current.FindResource("FireGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imFire, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire, null);
}
}
private static void ShowDoorPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainRight trainLeft = (TrainRight)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor,
(ImageSource)Application.Current.FindResource("DoorGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imDoor, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor, null);
}
}
}
public partial class TrainLeft : UserControl
{
public static readonly DependencyProperty TrainNameProperty =
DependencyProperty.Register("TrainName", typeof(string), typeof(TrainLeft));
public static readonly DependencyProperty ShowFireProperty =
DependencyProperty.Register("ShowFire", typeof(bool), typeof(TrainLeft), new
PropertyMetadata(false, ShowFirePropertyChanged));
public static readonly DependencyProperty ShowDoorProperty =
DependencyProperty.Register("ShowDoor", typeof(bool), typeof(TrainLeft), new
PropertyMetadata(false, ShowDoorPropertyChanged));
public bool ShowFire
{
get { return (bool)GetValue(ShowFireProperty); }
set { SetValue(ShowFireProperty, value); }
}
public bool ShowDoor
{
get { return (bool)GetValue(ShowDoorProperty); }
set { SetValue(ShowDoorProperty, value); }
}
public string TrainName
{
get { return (string)GetValue(TrainNameProperty); }
set { SetValue(TrainNameProperty, value); }
}
private ElementAdorner _elementAdorner = default!;
public TrainLeft()
{
InitializeComponent();
DataContext = this;
MouseMove += DragControl_MouseMove;
PreviewGiveFeedback += DragControl_PreviewGiveFeedback;
}
private void DragControl_PreviewGiveFeedback(object sender, GiveFeedbackEventArgs e)
{
_elementAdorner.SetArrange(this);
}
private void DragControl_MouseMove(object sender, MouseEventArgs e)
{
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
_elementAdorner = new ElementAdorner(this);
adornerLayer.Add(_elementAdorner);
DragDrop.DoDragDrop(this, this.DataContext, DragDropEffects.Copy);
adornerLayer.Remove(_elementAdorner);
}
private static void ShowFirePropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainLeft trainLeft = (TrainLeft)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire,
(ImageSource)Application.Current.FindResource("FireGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imFire, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imFire, null);
}
}
private static void ShowDoorPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
TrainLeft trainLeft = (TrainLeft)d;
bool show = (bool)e.NewValue;
if (show)
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor,
(ImageSource)Application.Current.FindResource("DoorGif"));
ImageBehavior.SetRepeatBehavior(trainLeft.imDoor, RepeatBehavior.Forever);
}
else
{
ImageBehavior.SetAnimatedSource(trainLeft.imDoor, null);
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78184245/drag-and-drop-feature-in-wpf[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия