Encapsulating dynamic mouse UI element in WPF appliation












1















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




















  • 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
    Nov 19 '18 at 10:32











  • 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
    Nov 19 '18 at 13:57
















1















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




















  • 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
    Nov 19 '18 at 10:32











  • 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
    Nov 19 '18 at 13:57














1












1








1








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
















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















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 10:33







Marmarello

















asked Nov 19 '18 at 10:25









MarmarelloMarmarello

63




63








  • 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
    Nov 19 '18 at 10:32











  • 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
    Nov 19 '18 at 13:57














  • 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
    Nov 19 '18 at 10:32











  • 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
    Nov 19 '18 at 13:57








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
Nov 19 '18 at 10:32





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
Nov 19 '18 at 10:32













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
Nov 19 '18 at 13:57





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
Nov 19 '18 at 13:57












0






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',
autoActivateHeartbeat: false,
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
});


}
});














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

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




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

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)