Binding to viewmodel from inside a datatemplate
Command=”{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.StartVideo}”
Command=”{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.StartVideo}”
On automapper where you create the Map you can specify additional processes for specific members of the destination type. So where your default map would be Mapper.Map<Domain.User, UsersDetailsViewModel>(); there is a fluent syntax to define the more complicated mappings: Mapper.Map<Domain.User, UsersDetailsViewModel>() .ForMember(vm=>vm.UserName, m=>m.MapFrom(u=>(u.UserName != null) ? u.UserName : “User” + u.ID.ToString())); Here the ForMember takes … Read more
I inject a service into the controller, not a repository, and then use AutoMapper to convert it into a view model. The benefit of the service layer in this case is that it could aggregate multiple simple operations from one or more repositories into a single operation exposing a domain model. Example: private readonly ICustomerService … Read more
If you’re using something supporting DataAnnotations, you should be able to use a metadata class to contain your validation attributes: public class ProductMetadata { [NotEmpty, NotShorterThan10Characters, NotLongerThan100Characters] public string Name { get; set; } [NotLessThan0] public decimal Price { get; set;} } and add it in the MetadataTypeAttribute on both the domain entity & DTO: … Read more
Nested subviews can be resolved by using v-view and v-ref. html <div id=”main”> <div v-view=”currentView” v-ref=”view”></div> </div> <ul> <li><a href=”#/”>top</a></li> <li><a href=”#/nest/view1″>nest/view1</a></li> <li><a href=”#/nest/view2″>nest/view2</a></li> </ul> <script id=”top” type=”x-template”> <div>top view</div> </script> <script id=”nest” type=”x-template”> <div> <span>nest view</span> <div v-view=”subview”></div> </div> </script> javascript Vue.component(‘top’, Vue.extend({ template: “#top”, })); Vue.component(‘nest’, Vue.extend({ template: ‘#nest’, components: { view1: Vue.extend({ … Read more
From version androidx.hilt:hilt-navigation-compose:1.0.0-alpha02 you can inject view model into Composable functions by: hiltViewModel<ViewModelType>() Example: @Composable fun LoginScreen(viewModel: LoginViewModel) {} LoginScreen( viewModel = hiltViewModel<LoginViewModel>() ) Android Developer Documentation compose and hilt UPDATE: import androidx.hilt.navigation.compose.hiltViewModel @Composable fun LoginScreen( viewModel: LoginViewModel = hiltViewModel() ){ val videos=vm.watchLater.observeAsState() val context= LocalContext.current }
This happens because of how the DialogFragment is created. If you use onCreateDialog() than a slightly different lifecycle is used for this type of Fragment. The onCreateView() will not be used, thus the viewLifecycleOwner for this Fragment won’t be initialized. As a workaround for this, you can use the Fragment instance as the owner for … Read more
A rather challenging question to answer succinctly, but I’ll attempt it. (Bear in mind that the answers to these kinds of questions are still the subject of debate amongst developers.) In MVC, the ViewModel provides all the information necessary for a View to be rendered. The data it contains is created using data defined in … Read more