Encapsulating dynamic mouse UI element in WPF appliation











up vote
1
down vote

favorite












I am developing a C# WPF application utilizing MVVM pattern



In my app user via mouse (or touchscreen) sets offset values for the Pan-Tilt Motor. Since movement should be somwhat percise, I decided to create a UI helper element, which currently looks like this:



screenshot



I want it to look nice and dandy, so that values wont be obscured or intersected with other lines:



obscured or intersected with other lines



But at the same time I want to stick to MVVM pattern, and such behaviour, although not hard to implement per se, requires a lot of bindings, logic and triggers. That clutters my XAML and View Model a lot, so here comes my question:



What is the common way/best practice of encapsulating such element (which is basically a complex dynamic figure) into some abstract form, hiding all irrelevant to the main app logic within it?



The desired solution wold look something like this:



<canvas>
<i:Interaction.Triggers>
<!--MouseUp, MouseDown, MouseMove Commands...-->
</i:Interaction.Triggers>

<i:Interaction.Behaviors>
<!--Getting Mouse X and Y values...-->
</i:Interaction.Behaviors>

<MouseUI MouseUiClass="{Binding MouseUiClass}"/>
or
<MouseUI Start="{Binding MouseUiClass.Start}"
End="{Binding MouseUiClass.End}"
IsFinished="{Binding MouseUiClass.IsFinished}"/>
</canvas>


I did consider to use UserControl but I struggle to understand how to properly display it because dynamically resizes, and start and end point can be placed in any part of canvas.










share|improve this question









New contributor




Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    UserControl is a good way to encapsulate the UI-related XAML and code in one place. I would do the positioning of the labels in code-behind. It doesn't break MVVM because it's purely UI-related code.
    – dymanoid
    yesterday










  • Honestly I would just draw that text with a thick white outline so the lines don't affect readability. Other than that, as for encapsulating this logic, if you like XAML then UserControl, if you prefer C# then a custom behavior or attached property (though I prefer behaviors).
    – bokibeg
    yesterday















up vote
1
down vote

favorite












I am developing a C# WPF application utilizing MVVM pattern



In my app user via mouse (or touchscreen) sets offset values for the Pan-Tilt Motor. Since movement should be somwhat percise, I decided to create a UI helper element, which currently looks like this:



screenshot



I want it to look nice and dandy, so that values wont be obscured or intersected with other lines:



obscured or intersected with other lines



But at the same time I want to stick to MVVM pattern, and such behaviour, although not hard to implement per se, requires a lot of bindings, logic and triggers. That clutters my XAML and View Model a lot, so here comes my question:



What is the common way/best practice of encapsulating such element (which is basically a complex dynamic figure) into some abstract form, hiding all irrelevant to the main app logic within it?



The desired solution wold look something like this:



<canvas>
<i:Interaction.Triggers>
<!--MouseUp, MouseDown, MouseMove Commands...-->
</i:Interaction.Triggers>

<i:Interaction.Behaviors>
<!--Getting Mouse X and Y values...-->
</i:Interaction.Behaviors>

<MouseUI MouseUiClass="{Binding MouseUiClass}"/>
or
<MouseUI Start="{Binding MouseUiClass.Start}"
End="{Binding MouseUiClass.End}"
IsFinished="{Binding MouseUiClass.IsFinished}"/>
</canvas>


I did consider to use UserControl but I struggle to understand how to properly display it because dynamically resizes, and start and end point can be placed in any part of canvas.










share|improve this question









New contributor




Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    UserControl is a good way to encapsulate the UI-related XAML and code in one place. I would do the positioning of the labels in code-behind. It doesn't break MVVM because it's purely UI-related code.
    – dymanoid
    yesterday










  • Honestly I would just draw that text with a thick white outline so the lines don't affect readability. Other than that, as for encapsulating this logic, if you like XAML then UserControl, if you prefer C# then a custom behavior or attached property (though I prefer behaviors).
    – bokibeg
    yesterday













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am developing a C# WPF application utilizing MVVM pattern



In my app user via mouse (or touchscreen) sets offset values for the Pan-Tilt Motor. Since movement should be somwhat percise, I decided to create a UI helper element, which currently looks like this:



screenshot



I want it to look nice and dandy, so that values wont be obscured or intersected with other lines:



obscured or intersected with other lines



But at the same time I want to stick to MVVM pattern, and such behaviour, although not hard to implement per se, requires a lot of bindings, logic and triggers. That clutters my XAML and View Model a lot, so here comes my question:



What is the common way/best practice of encapsulating such element (which is basically a complex dynamic figure) into some abstract form, hiding all irrelevant to the main app logic within it?



The desired solution wold look something like this:



<canvas>
<i:Interaction.Triggers>
<!--MouseUp, MouseDown, MouseMove Commands...-->
</i:Interaction.Triggers>

<i:Interaction.Behaviors>
<!--Getting Mouse X and Y values...-->
</i:Interaction.Behaviors>

<MouseUI MouseUiClass="{Binding MouseUiClass}"/>
or
<MouseUI Start="{Binding MouseUiClass.Start}"
End="{Binding MouseUiClass.End}"
IsFinished="{Binding MouseUiClass.IsFinished}"/>
</canvas>


I did consider to use UserControl but I struggle to understand how to properly display it because dynamically resizes, and start and end point can be placed in any part of canvas.










share|improve this question









New contributor




Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am developing a C# WPF application utilizing MVVM pattern



In my app user via mouse (or touchscreen) sets offset values for the Pan-Tilt Motor. Since movement should be somwhat percise, I decided to create a UI helper element, which currently looks like this:



screenshot



I want it to look nice and dandy, so that values wont be obscured or intersected with other lines:



obscured or intersected with other lines



But at the same time I want to stick to MVVM pattern, and such behaviour, although not hard to implement per se, requires a lot of bindings, logic and triggers. That clutters my XAML and View Model a lot, so here comes my question:



What is the common way/best practice of encapsulating such element (which is basically a complex dynamic figure) into some abstract form, hiding all irrelevant to the main app logic within it?



The desired solution wold look something like this:



<canvas>
<i:Interaction.Triggers>
<!--MouseUp, MouseDown, MouseMove Commands...-->
</i:Interaction.Triggers>

<i:Interaction.Behaviors>
<!--Getting Mouse X and Y values...-->
</i:Interaction.Behaviors>

<MouseUI MouseUiClass="{Binding MouseUiClass}"/>
or
<MouseUI Start="{Binding MouseUiClass.Start}"
End="{Binding MouseUiClass.End}"
IsFinished="{Binding MouseUiClass.IsFinished}"/>
</canvas>


I did consider to use UserControl but I struggle to understand how to properly display it because dynamically resizes, and start and end point can be placed in any part of canvas.







c# wpf user-interface mvvm






share|improve this question









New contributor




Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday





















New contributor




Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Александр Теплов

63




63




New contributor




Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Александр Теплов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




    UserControl is a good way to encapsulate the UI-related XAML and code in one place. I would do the positioning of the labels in code-behind. It doesn't break MVVM because it's purely UI-related code.
    – dymanoid
    yesterday










  • Honestly I would just draw that text with a thick white outline so the lines don't affect readability. Other than that, as for encapsulating this logic, if you like XAML then UserControl, if you prefer C# then a custom behavior or attached property (though I prefer behaviors).
    – bokibeg
    yesterday














  • 2




    UserControl is a good way to encapsulate the UI-related XAML and code in one place. I would do the positioning of the labels in code-behind. It doesn't break MVVM because it's purely UI-related code.
    – dymanoid
    yesterday










  • Honestly I would just draw that text with a thick white outline so the lines don't affect readability. Other than that, as for encapsulating this logic, if you like XAML then UserControl, if you prefer C# then a custom behavior or attached property (though I prefer behaviors).
    – bokibeg
    yesterday








2




2




UserControl is a good way to encapsulate the UI-related XAML and code in one place. I would do the positioning of the labels in code-behind. It doesn't break MVVM because it's purely UI-related code.
– dymanoid
yesterday




UserControl is a good way to encapsulate the UI-related XAML and code in one place. I would do the positioning of the labels in code-behind. It doesn't break MVVM because it's purely UI-related code.
– dymanoid
yesterday












Honestly I would just draw that text with a thick white outline so the lines don't affect readability. Other than that, as for encapsulating this logic, if you like XAML then UserControl, if you prefer C# then a custom behavior or attached property (though I prefer behaviors).
– bokibeg
yesterday




Honestly I would just draw that text with a thick white outline so the lines don't affect readability. Other than that, as for encapsulating this logic, if you like XAML then UserControl, if you prefer C# then a custom behavior or attached property (though I prefer behaviors).
– bokibeg
yesterday

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Александр Теплов is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372571%2fencapsulating-dynamic-mouse-ui-element-in-wpf-appliation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Александр Теплов is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Александр Теплов is a new contributor. Be nice, and check out our Code of Conduct.













Александр Теплов is a new contributor. Be nice, and check out our Code of Conduct.












Александр Теплов is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372571%2fencapsulating-dynamic-mouse-ui-element-in-wpf-appliation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$